This is the scenario: you want to set a cron job and the script you want to use runs correctly when called from the command line, but when you run the same script with crontab, it does not work. More than likely, this problem is caused by the default shell environment variables setup by crontab. Cron supplies a default (bare) environment for every shell:
HOME=user's-home-directory LOGNAME=user's-login-id PATH=/usr/bin:/usr/sbin:. SHELL=/usr/bin/sh
Here are a few solutions:
* Explicitly enter the needed environment variables. * Load your .profile in the crontab or in the script called by crontab. * Use the absolute path for every command run in the script.
Here is a simple test to know exactly what variables are different, or even missing, in the crontab environment:
From the shell prompt, enter:
$ env > /tmp/myenv.log
Then set a cron job to do the same from the crontab.
$crontab -e * * * * * env > /tmp/crontabenv.log :wq
This line in the crontab will execute every minute, and store the environment variables in /tmp/crontabenv.log . diff both files to find the differences.
Use the env command to set the enviroment you need for your script to run.
man env info env
for more information
This was written using info from: http://blog.spikesource.com/crontab.htm