Monday, 14 August 2017

linux mint - Schedule a cronjob everytime it is done


I have a cronjon which runs every 48 hours. But ideally what I want is that it must start running as soon as it stops. Can this be done? It is an sh script consisting of a python command. I am using Linux Mint 13.


Thank you



Answer



One thing you could do is run the python command in an infinite loop, and then run the script once using cron. That way the script will be run again each time it finishes:


#!/bin/bash
while true; do ## Enter infinite loop
sleep 5; ## Wait for 5 seconds
python -c 'print("hello world")' ## Run your python command
done

If you save that script as, for example, ~/run_python.sh and make it executable (chmod +x ~/run_python.sh), you can set it to run once on system boot using the @reboot prefix. Add this line to your crontab:


@reboot ~/run_python.sh

So, the BASH script will start on system boot and it will wait 5 seconds, run the python command and then keep doing so indefinitely.


A better, or at least more *nixy, way of doing this would be to add script to /etc/init.d.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...