Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

  1. wrapper script that calls a random_sleep_interval script
  2. The random_sleep_interval script itself
  3. 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:

random_sleep_interval 100

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

share|improve this question
    
You sure there is not a bug in your script? From moundalexis.com/archives/000076.php #!/bin/sh # Grab a random value between 0-240. value=$RANDOM while [ $value -gt 240 ] ; do value=$RANDOM done # Sleep for that time. sleep $value –  grm Jan 28 '11 at 11:00
    
would you mind showing us more of your wrapper script? what script creates the logfiles? have you tried to fail the script if random_sleep_interval returns a non zero value? are the scripts all in crons path? as you see, there is not enough information given to effectively approach your problem –  matthias krull Jan 28 '11 at 13:07
    
It seems that $RANDOM is not as random as the name may suggest. Most of the numbers were falling withing the 0 <= x < 60 second. Thus giving the illusion that the sleeper script was not working (since file time resolution [at least the DEFAULT] resolution is to the minute only. This question can now be closed. Thanks to grm and mugen though .. –  Takashi Jan 28 '11 at 15:00
    
Without posting the random sleep script, we can only guess. Also, show the wrapper script as previously suggested by mugen kenichi. –  Dennis Williamson Jan 28 '11 at 17:12
    
I'd add a set -x to the scripts, starting with the wrapper script, and then the sleep script, and see what errors you get. You did set up your crontab to send you email with MAILTO=youremail@somewhere.org right? –  Rich Homolka Jan 29 '11 at 0:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.