Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running a python script with cron

Tags:

python

cron

It might be very simple question, but how could I run a python script on my fedora dist every 2 days?

Thanks

Antonis

like image 542
Antonis Avatar asked Dec 16 '10 11:12

Antonis


People also ask

Can we schedule Python script in crontab?

First, create your Python script. Then, open the system terminal your working with. To access crontab, input 'crontab -e' (one will be created if it doesn't already exist). Then enter 'i' to initiate the edit mode, and proceed to input your schedule command.

How do I schedule a Python script?

Double-click on the Task Scheduler, and then choose the option to 'Create Basic Task…' Type a name for your task (you can also type a description if needed), and then press Next. For instance, let's name the task as: Run Hello World. Choose to start the task 'Daily' since we wish to run the Python script daily at 6am.


1 Answers

It is a question on cron. First is add a SHEBANG line on top of your python script.

#!/usr/bin/env python 

Make your script executable with chmod +x

And do a crontab -e and add 0 0 */2 * * /path/to/your/pythonscript.py

like image 141
Senthil Kumaran Avatar answered Sep 20 '22 02:09

Senthil Kumaran