Zuriar
Zuriar

Reputation: 11734

Cron not running for user

I want a user (tcff) to run two python scripts at 2am every morning.

I have correctly installed the following crontab for this user:

tcff@mymachine> crontab -l

0 2 * * * python /home/tcff/path/to/myscript1.py
0 2 * * * python /home/tcff/path/to/myscript2.py

The permissions for each script are:

-rwxr-xr-x 1 tcff tcff  5522 Sep 25 12:41 myscript1.py
-rwxr-xr-x 1 tcff tcff  5522 Sep 25 12:41 myscript2.py

When I call each script directly they work fine:

tcff@mymachine> python /home/tcff/path/to/myscript1.py

[Output as expected]

However they are not being run by cron at 2am each morning.

I can't work this out. I am sure I have the permissions correct etc?

Upvotes: 0

Views: 114

Answers (2)

Altmish-E-Azam
Altmish-E-Azam

Reputation: 1583

First of all give full permission to script file.

chmod 777 script_name

Also trace the logs of crontab and see what is happening with cronjob here you can see all logs of crontab. May be there is any exception or error.

root@localhost:[~]: tail -f /var/log/cron

Upvotes: 0

Zuriar
Zuriar

Reputation: 11734

Yes, indeed, the reason the scripts were not running is because I did not use the full path to the Python binary:

0 2 * * * /usr/bin/python /home/tcff/path/to/myscript2.py

This is needed because although the shell (bash) has /usr/bin on the PATH the process running cron does not.

Upvotes: 1

Related Questions