Cronjob not running on Ubuntu 14.04

I have created a test cronjob using crontab -e that runs a script at /home/cmccabe/cron.sh . I am not sure the script doesn't run though I can call it in terminal. Thank you :).

crontab -e (run script sat at 6:10pm)?

10 18 * * 6 /home/cmccabe/cron.sh

contents of cron.sh

#!/bin/bash
echo "Is it 6:10pm?"

I can see the service is running, but the cronjob does not execute.

pgrep cron
17707

It probably is running.

#!/bin/bash
echo "Is it 6:10pm?" > /home/mcccabe/somefile.txt

Try that, also when there is output from a cronjob like yours did, that writes to stdout,
output went to email - the email account for you on your linux box.

Other important point: NONE of your environment variables are available to the job run under cron.

#!/bin/bash
source  /home/mccabe/.profile  # or where you have the process setup code
echo "Is it 6:10pm?" > /path/to/somefile.txt

There are loads of ways to do this, above is just a simple example....

1 Like

While I'm at it: quick debug of a crontab entry:
Example:
it is Friday as 22:00pm exactly so set your job for 2 minutes in the future:
create your job with crontab like:

2 22 * * *  /home/cmccabe/test.sh

wait 3 minutes, check your expected output - email or whatever.
Remove the test cron entry. Wash, rinse, repeat until you have your code working AND you have it running as expected.

Also note the "6" you have in your original entry will be different in different locales. Some places the week starts with Monday, other days, Sunday. So I cannot tell what day you are looking at.

Also check out anacron - allows you to turn off the machine and have jobs run anyway, later at the first chance.

1 Like

Thank you very much, I guess i thought it would write to stdout and I would see the terminal displayed. Thanks again :).

First i would check in that setup is does the script in question has an execute permission for, at least, user in which cron is set.

Also, script should echo the defined time with day :wink:

10 18 * * 6 echo "Is it 6:10pm, Saturday, since last number in crontab entry is 6"
1 Like

Thank you very much for the helpful tip :), I appreciate it.