need help with small background-running bash script

Discussion in 'Mac Programming' started by Asu, Dec 24, 2008.

  1. Asu macrumors member

    Asu

    Joined:
    Apr 28, 2006
    #1
    Hello Mavens,

    I need help (as in "Pretty please tell me exactly how to do it...") with the following task.

    Code:
    while running in the background
    (at random intervals (between 0.5 and 5 minutes)) (do a command)
    that's it!

    TIA and Merry (OS)Xmas

    Asu
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Code:
    until [ 1 -eq 2 ]
    do
      ....
      let "sleepval = $RANDOM % 271 + 30"
      sleep $sleepval
    done
    
    No guarantees, this was written on my phone. The principle should be clear, though. In ...'s place you put what you want to run, then get a random value from 0 to 270, then add 30. This is the amount of time in seconds to sleep.

    There is quite likely a better way, but I think this should work.

    -Lee
     

Share This Page