panchicore
panchicore

Reputation: 11932

How to know if cronjob is failing (running a python command)

When I run this command, the output message is being saved into ok.txt:

 /home/admin/virtualenvs/x.com/bin/python /home/admin/www/x.com/x/app/manage.py help | tee ok.txt

I have this cronjob:

* * * * * /home/admin/virtualenvs/x.com/bin/python /home/admin/www/x.com/x/app/manage.py help | tee ok.txt

But nothing is saved to ok.txt

When I see the cron log

> sudo grep CRON /var/log/syslog

May 10 22:16:01 localhost CRON[23397]: (admin) CMD (/home/admin/virtualenvs/x.com/bin/python /home/admin/www/x.com/x/app/manage.py help | tee ok.txt)

No hints here, what am I doing wrong? thanks in advance.

Upvotes: 3

Views: 1414

Answers (2)

user1403360
user1403360

Reputation: 929

first i see that you don't have the correct syntax for crontab:

Example of job definition:
.---------------- minute (0 - 59)
|  .------------- hour (0 - 23)
|  |  .---------- day of month (1 - 31)
|  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
|  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
|  |  |  |  |
*  *  *  *  * user-name command to be executed

you are missing the user-name.

And the second thing. Don't assume that your .bashrc is loaded. In cron you just get the environment that is defined on top of the file. So if your script is using something that you have defined in your bashrc then it might be, that it doesn't execute correctly.

Upvotes: 0

Cédric Julien
Cédric Julien

Reputation: 80771

try with this :

* * * * * /home/admin/virtualenvs/x.com/bin/python /home/admin/www/x.com/x/app/manage.py help > /tmp/ok.txt 2&>1

it should put all outputs (stderr and stdout) into your ok.txt file

Upvotes: 1

Related Questions