2

I'm trying to automatically run a script once every minute. But it might take more than 1 minutes sometimes & hence I have to have a lock on the script while it is running so that only one instance of the script can run at any given time.

My cronjob is as follows,

* * * * * root /usr/bin/flock -w 0 /var/cron.lock /pythonScripts/readPushData.py

My python script is set an executable using,

chmod a+x readPushData.py

The python compiler is set at the top of the script like,

#!/usr/bin/python3.5

The script can be run manually using './readPushData.py', but when I try to run it using a cronjob it doesn't work. Why is this happenning?

1 Answers1

1

I found the solution for running one instance of my script at a time using this [https://raspberrypituts.com/raspberry-pi-simple-cron-jobs-explanation/][1]

Then I used the following in /etc/cron.d/python to setup the cronjob

* * * * * root /usr/bin/python3.5 /pythonScripts/readPushData.py

Then I rebooted the system. It works like a charm. Thank you all for your comments!