简体   繁体   中英

Python + Linux: How to determine cron job is scheduled?

Currently, I've scheduled a python script on Linux by adding the following: */10 * * * * /file/testscripts/test_script.py to crontab -e .

It did not run after 10 minutes, so I wrote some code to write the current time on there but wasn't being updated either.

What could be the issue? And how can I determine my python script has been scheduled for a cron job properly?

Thank you in advance and will accept/upvote answer

There are plenty things you could do:

  • Try to set full path to python interpreter as well as the script name.
  • Pipe stdout/stderr to a log file and print something out: ... test_script.py > /tmp/pythonCron.log 2>&1
  • Is the cron service enabled and running ?

As FamousJameous pointed out, when the cron job was started, you should see some lines in /var/log/syslog:

May 15 06:29:00 xyz CRON[9368]: (www-user) CMD (python ...

Try with 10 * * * * yourscript name.Then check if crontab -l is include your script. Then you can check crontab logs.

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