简体   繁体   中英

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM