Sleeping for a random amount of time in a shell script
Ever want to make a shell script pause…
You can use the special $RANDOM environment variable to get a random number and then divide it by the maximum number of seconds that you want to wait. Use the remainder as the number of seconds to sleep since it will always be between zero and the max you specified. This example will sleep anywhere between zero and 10 minutes (600 seconds)
/bin/sleep/sleep `/usr/bin/expr $RANDOM % 600`
Of course – those who really are keen will note that it isn’t truly random. The maximum value for $RANDOM is 32767 which is not evenly divisible by most likely values – but its close enough for me
Tags: shell scripting, sleeping
Pages
Tags
apple Archived asperger's autism blogging cat6 Chatter Church cisco citrt comcast convention cPanel datacenter debugging mysql devil evangelism facebook faith family iPad iPhone iscsi Leadership Linux MAC Marketing Microsoft MySQL network Off the wall crazy OpenSource or just weirdly different pfsense politics Ramblings review Security skype Sprint Storage Technology Web 2.0 minus or plus Wifi wisp


Place your comment