I have the following cron job running a Python script which seems to install okay with no issues after creating it in Crontab and saving (this is on a server running Centos7). I'm not seeing either a log file nor any output sent in to the email address included. I've tried this:
*/2 * * * * /home/local/DEV/mdub/FTWFB/FTWFBUploader.py > /home/local/DEV/mdub/FTWFB/logs`date +\%Y-\%m-\%d-\%H:\%M:\%S`-cron.log 2>&1 | mailx -s “Facebook Uploads - Cronlog" mdubs@gmail.com
and this:
*/2 * * * * /home/local/DEV/mdub/FTWFB/FTWFBUploader.py | tee /home/local/DEV/mdub/FTWFB/logs`date +\%Y-\%m-\%d-\%H:\%M:\%S`-cron.log | mailx -s “Facebook Uploads - Cronlog" mdubs@gmail.com
What am I doing wrong?
On both files I ran chmod +x (filename)
and when I manually run the scripts they run and output as expected.
Best Answer
Firstly, when configuring a crontab use the full path for any commands and scripts you are calling. For example:
tee
should be/usr/bin/tee
mailx
should be/bin/mailx
date
should be/bin/date
Note: If the paths are different on your system change as appropriate
Also, chaining commands in a crontab (i.e. piping,
|
) can get messy very quickly. It might be better to put those commands in a script and call that from cron instead.If that doesn't help follow these general troubleshooting steps for cron:
Verify that
crond
is enabled and running, for example:Check the cron logs to see if any errors show up in there (replace
UserName
with the name of the user):Check that user's mail file to see if any cron output is showing up there:
If all else fails, append a redirect at the end of the crontab entry to help catch any spurious errors that might arise. For example instead of this:
Do this: