Cron jobs in Ubuntu

强颜欢笑 提交于 2019-12-11 08:24:00

问题


How to run a cron job in ubuntu in such a way that it should initiate a python script?

Please explain with a small example.


回答1:


You can set a simple line to run from x to x time:

e.g.,

0,10,20,30,40,50 * * * * ~/py/my_python_script.py

runs every 10 minuts

STEP BY STEP USING VIM AS THE SELECTED EDITOR

  1. At your terminal, run: sudo crontab -e

  2. Afterwards, choose you favorite editor (e.g., vim)

  3. type :i and hit enter to insert a new line

  4. Past or write the cronjob line 0,10,20,30,40,50 * * * * ~/py/my_python_script.py and hit enter and then return to exit that line

  5. type :w and hit enter, to write the file

  6. type :q and hit enter to exit

Description for the asterisks:

minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command 

In-deep:

To read a more detailed process on how it all works:

CronHowto

VIM Commands Cheat Sheet




回答2:


You can run Crontab in Ubuntu. Simply just copy and paste the following script in the terminal.

crontab -e

There you can write command for run your python script, that will execute the program in a specific time interval.

* * * * *   python   </path/to/the/file>

You can refer the link for the time interval

You can check the log file here

tail -f /var/log/syslog


来源:https://stackoverflow.com/questions/10720466/cron-jobs-in-ubuntu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!