Sasikiran Vaddi
Sasikiran Vaddi

Reputation: 2309

Cron jobs in Ubuntu

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.

Upvotes: 1

Views: 5234

Answers (2)

Girish Vas
Girish Vas

Reputation: 680

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

Upvotes: 0

Zuul
Zuul

Reputation: 16269

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

Upvotes: 3

Related Questions