I need to monitor intrusion on a server at (relatively) random intervals. For that I have set up a cron job to run every hour.
I have written three scripts:
- wrapper script that calls a random_sleep_interval script
- The random_sleep_interval script itself
- The worker script that does the monitoring work (and logs to file)
The random_sleep_interval works by itself in that when I type it at the CLI like this:
It outputs something like this:
Sleeping for 95 seconds ...
Where 95 is a random time interval calculated/selected by the random_sleep_interval script. Every time the script is run, it sleeps for a random number of seconds (between 0 and the first agument passed to the script)
The wrapper script is successfully invoked by cron. The wrapper script then in turn calls the random_sleep_interval and the worker script. However, when I check the logs created by the worker script, all the log files are created at the SAME TIME that the cron job starts - meaning that somehow, the sleep part is not working.
Can someone explain to me why together, they dont work but seprately it works (as explained above)?
The only reason for this behaviour is if the wrapper script is spawning different processes for each script to be run - but that does not make sense...
I am running on Ubuntu 10.0.4 LTS