views:

395

answers:

4

I'm trying to execute a shell script from cron on Freebsd.

To test wether crontab is working at all, i wrote the line
* * * * * echo "Hello" > /home/myuser/logile
and it work fine.

But when trying to execute any script it doesn't do anything, not even an error. (In the script i tried to run is just the same echo command) Below is the output of crontab -l:

SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
HOME=/home/myuser
MAILTO=myuser
* * * * * /home/myuser/shellscript.sh > /home/myuser/logfile

why is the script not getting executed, although crontab is obviously running? permission for all files are set to rwxr-xr-x

A: 

Have you tried

* * * * * /bin/sh /home/myuser/shellscript.sh > /home/myuser/logfile 
Alberto Zaccagni
yes i tried that, but no reaction.
crontabOnFreebsd
A: 

If you are getting an error, then your logfile might not capture it, try this:

* * * * * /home/myuser/shellscript.sh > /home/myuser/logfile 2> /home/myuser/errorfile

Its been a while since I did any cron stuff; but things that always used to get me:

  1. Environment variables not been set: generally I found it necessary to set up full paths (even to things like 'cat') to all commands [or at least set ENV variables within the script itself].

  2. Ensure the user who owns the script etc is really the user which is running the script: this might not be the same user when you test from the interactive shell. Same goes for the directories/files that the script might write to.

  3. Also: check the email for the root user - you might find that the errors have been diverted to the inbox, which may help you troubleshoot this further.

monojohnny
+1  A: 

cron sends any errors via email to owner of the crontab file (often "root" so you might check that account's email). To have any errors mailed to "crontabOnFreebsd" put:

MAILTO=crontabOnFreebsd

in your crontab (near the top).

For more info issue this command:

man 5 crontab
Perry
+1  A: 

Have you checked /var/log/cron for clues?

coneslayer