[ILUG] Bash script - technical question

Gareth 'bigbro' Eason bigbro at skynet.ie
Mon Nov 1 08:35:15 GMT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 30/10/10 17:05, David Pintor wrote:
> Hi,
> 
> Thanks for your responses... :-)
> 
> Just in case anyone's interested, I found a more or less nice way to do
> this, using a file that stores the seconds and using both sleep and the
> crontab...
> 
> Basically:
> 
> if interval >= 1 min
>    sleep ` cat secs.txt`
[snip]

	Note that Cron does not guarantee to run things at :00 seconds, so if
you are looking to run a script at accurately spaced intervals it sounds
to me like an ideal use of a daemon (which can use sleep and a couple of
other checks to ensure accuracy depending on the level required.)

	I had what sounds like a similar to yours some time ago and I found
that the simplest, most reliable and most accurate way of achieving this
was to write the script as a daemon, including appropriate /etc/init.d/
scripts in place such that it was stopped and started correctly on
system shutdown/restart.

	A quick google yields
http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html which
appears to be a very reasonable and simple tutorial (in C.) If you have
a script that already contains the functionality you require, remember
you can always just call that script from within the C daemon code,
being careful of security issues (i.e. can someone replace the shell
script and get your daemon to them run their code as root, or similar?)

	In my case I also wrote a small crontab job to make sure that the
daemon was still running, restarting it and raising an alarm if it
discovered the daemon process wasn't there. This made a fairly reliable
method of definitely running some process at fairly accurate fixed time
intervals.

	Hope this helps.

	Best regards,
	-->Gar


	Hope that helps.

	
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzOe8IACgkQK36C50PvIR8DWQCfZt24zhiXdAjB4jXihukGovei
R6sAniYBwJQ0ehZ0do/EoscwxtwiloKA
=QLKU
-----END PGP SIGNATURE-----


More information about the ILUG mailing list