Reputation: 7280
Following is the entry in the crontab:
[email protected]
45 14 * * * /home/user/simple.sh
I've also done chmod +x
on the simple.sh
But the crontab does not run, it doesn't even send an email.
pgrep cron
shows an Id. I also tried bouncing crond. But no luck!
Could someone please point out the mistake here
The simple.sh script is:
#! /bin/bash
echo hello
Thanks
Upvotes: 4
Views: 6264
Reputation: 4930
Maybe there shouldn't be a space in line 1 of your .sh script:
#! /bin/bash
to
#!/bin/bash
Although I could see why it would still seem to work from when invoked in an interactive shell (# could merely comment out the rest of the line).
Still, I'd guess at worst it'd merely ignore that line and inherit cron's interpreter of /bin/sh
Upvotes: 0
Reputation: 77013
Since you are doing a echo
within the cron job script, you need to capture its output somewhere.
Your shebang
and file mode (using chmod +x
) are all right, so those aren't the issue here and running without /bin/sh
should work fine.
Try using the following to see the output in cron.log
file (This runs every minute)
* * * * * /home/user/simple.sh >> /home/user/cron.log
Note that cron jobs run in separate subprocess shell, with reduced environment, so its output won't be visible on your terminal.
Regarding sending of email - you need to have some mail package (like postman
, mutt
etc) configured for the cron daemon to send out error mails.
Upvotes: 6
Reputation: 290175
Do not use relative paths, but absolute ones. Also, indicate the binary running the script, that is /bin/sh
(or whatever coming from which sh
):
45 14 * * * /bin/sh /path/to/script/simple.sh
Upvotes: 4