cron python file doesn't work on centos 7

2019-09-20 03:58发布

问题:

i'm trying to schedule my pythohn script into Centos 7 with cron. On my script at start i have added this:

#!/usr/local/bin/python

and this is my cron file that i have create into folder that contain python file

*/5 * * * * /usr/local/bin/python /home/Documents/SCRAPE_PYTHON/SCRAPE.py &>> /home/Desktop/log.txt

i have try to run the script into terminal by chmod +x and works fine. But whit this configuration when in terminal i set crontab .cron the job doesn't work. The log file set into cron file are not write and script not run. The script could be write some data into db and the db is always empty. Any help??? Thanks

回答1:

Type crontab -e in the shell, this will open the cron editor. Here copy paste the entire command.

*/5 * * * * /usr/local/bin/python /home/Documents/SCRAPE_PYTHON/SCRAPE.py &>> /home/Desktop/log.txt

Now press Esc key then type colon :wq! and press Enter key. This will install your cron. Your cron should run every 5 minutes.

Your standard output and error will be appended to /home/Desktop/log.txt.