2

I currently have a shell script that I manage to execute without cron using 'sh runScript' to run it whilst in the same folder. It's located in my root folder. To try and get cron to run it at start-up I input:

@reboot sh runScript

into the file and saved it. I then did a reboot however I'm certain it isn't running. I tried doing @reboot echo "hello world" and that also did not execute correctly. I feel like this has something to do with paths. Any suggestions?

EDIT: I should probably mention I'm using Alpine. I have also changed the top line of my script to be #!/bin/sh now instead of #!/bin/bash so that I can run it using the filename.

6
  • 1
    If it has something to do with paths then why don't you just specify the path? Nov 22, 2017 at 22:31
  • @IgnacioVazquez-Abrams I don't think it's the path any more.
    – WewLad
    Nov 22, 2017 at 22:42
  • How do you know your echo didn't work? Did you check your local mail? Nov 22, 2017 at 22:43
  • @IgnacioVazquez-Abrams Local mail? I know the original command didn't work because when I run it manually I usually see the process in 'top' however when I use cron it won't be there.
    – WewLad
    Nov 22, 2017 at 22:45
  • 1
    echo doesn't usually take long enough to hang around in the process list. Nov 22, 2017 at 22:46

1 Answer 1

0

Check your cron log if there was any try to run the script. On redhat it is usually /var/log/cron. If there is error with path, you will see it there (what actually cron tried to run).
Then, to double check, instead of trying echo, try to send anything to a file, for example date > /file_with_date.txt. Then check if the file was created and what time is in it.
Then check if cron daemon runs at all ;)
Then check rights on the file, execute bit, maybe selinux blocks access to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.