user7998549
user7998549

Reputation: 131

Cron job is not executing Python script

I have a script that should run every 30 min every day.

 30 * * * * python /home/pi/MyScript.py

I used every min to test it

 1 * * * * python /home/pi/MyScript.py

but it's not executing, did I used the wrong path? or is the minute not correctly?

Upvotes: 0

Views: 76

Answers (3)

Remolten
Remolten

Reputation: 2682

You misunderstand the syntax.

In your first example, you tell cron to run MyScript.py at the 30th minute of each hour (ie 10:30), not every 30 minutes.

In the second example, MyScript.py is run at the 1st minute of each hour (ie 10:01), not every minute.

You probably want to do this:

*/30 * * * * python /home/pi/MyScript.py

Now, your script will run every 30 minutes (at 10:00, 10:30, 11:00 etc.). You can change 30 to whatever interval you desire.

Upvotes: 2

Lakshya Kejriwal
Lakshya Kejriwal

Reputation: 1388

If you want to run something every 30 min then the crontab should be something like this

*/30 * * * * python /home/pi/MyScript.py

Or for every 1 min like this.

*/1 * * * * python /home/pi/MyScript.py

Upvotes: 3

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477607

Your line:

1 * * * * python /home/pi/MyScript.py

will not fire every minute. It will fire every hour when the number of minutes is equal to 1 so 00:01, 01:01, 02:01, etc. In order for the script to fire every minute, you should write:

* * * * * python /home/pi/MyScript.py

and in case you want the script to fire every 30 minutes, you can for instance write:

0,30 * * * * python /home/pi/MyScript.py

Now the script will fire at 00:00, 00:30, 01:00, 01:30, etc.

Upvotes: 0

Related Questions