PDA

View Full Version : Make a script work all the time



cazz
December 1st, 2012, 05:11 PM
What is the best idea to run a script all the time

I like to run a script every 60 sec and is is crontab the best idea or a deamon


I have never work with deamon before?

cybergalvez
December 1st, 2012, 07:03 PM
What is the best idea to run a script all the time

I like to run a script every 60 sec and is is crontab the best idea or a deamon


I have never work with deamon before?

it depends on what you are trying to do, will the script alway be done within the 60sec time limit? what happends if you start more than one instance of the sript?

In general crontab is designed to do exactly what you are asking run scrtipts at specific time intervals, however given the frequency you might want to simply have a deamon running all the time that can do what you need and monitor the outcome.

Sorry, I guess I would need more info before commiting to an answer

cazz
December 1st, 2012, 07:19 PM
Ahh ok

It going to read if a computer is close by ping it for me.
if it close by it going to active a camera so it take a snapshot.

So as long the computer is not close it going to take a picture every 60 sec.

pbrane
December 1st, 2012, 11:54 PM
Another way, without cron is to add this to the end of your script.


sleep $delay
exec $0


Where $delay would be whatever delay you want in seconds. And exec $0 simply executes this script again.

cazz
December 1st, 2012, 11:57 PM
Hmm ok

I can do it three way then

I try now with crontab to see if it works and does not use to much CPU or anything like that.

KdotJ
December 2nd, 2012, 01:11 AM
Chances are, cron is already running on your machine anyway
.. so CPU cycles shouldn't be an issue as far as cron is concerned