I need to run application in every X seconds, so, as far as cron does not work with seconds this way, I wrote a bash script with infinite loop having X seconds sleep in it.
When I have to stop the running script manually, I would like to do it in a correct way – let the application complete functioning and just do not enter the loop for the next time.
Do you have any idea, how this can be achieved?
I thought about passing arguments, but I could not find how to pass argument to running script.
You could trap a signal, say SIGUSR1:
Then, when you want to exit the loop at the next iteration:
Where
pidis the process-id of the script. If the signal is raised during the sleep, it will wake (sleep sleeps until any signal occurs).