Reputation: 2309
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
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
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
At your terminal, run: sudo crontab -e
Afterwards, choose you favorite editor (e.g., vim)
type :i
and hit enter
to insert a new line
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
type :w
and hit enter
, to write the file
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
To read a more detailed process on how it all works:
Upvotes: 3