Results 1 to 10 of 10
Does anyone here knows how to make a random sleep of a maximum desired duration?.
for example i want execute wget after a time that may vary from 0 to ...
- 07-04-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 13
random sleep
Does anyone here knows how to make a random sleep of a maximum desired duration?.
for example i want execute wget after a time that may vary from 0 to 2 hours
thanks a lot!
- 07-05-2007 #2Just Joined!
- Join Date
- Jun 2007
- Posts
- 13
When i do this in a terminal window it works fine:
value=$RANDOM
echo $value
but in a script it does not works WHYYYYY!!!!???????
#!/bin/bash
value=$RANDOM
echo $value
PLEASE HELP!!!
- 07-05-2007 #3Linux User
- Join Date
- Jun 2007
- Posts
- 318
It doesn't work in a script? Sure you don't have a typo because it works for me. This is what I came up with:
value=$RANDOM
ct=`echo "scale=0; $value / 4.5509722" | bc`
sleep $ct
RANDOM returns a no. between 0 and 32767. The 4.5509722 scales it down to 0 and 7200 (0 to 2 hours).
- 07-05-2007 #4Just Joined!
- Join Date
- Jun 2007
- Posts
- 13
huge problem
Please i've tried what you suggested, in a term window it works but in a .sh file it does not.
Whats going on????
- 07-05-2007 #5Just Joined!
- Join Date
- Jun 2007
- Posts
- 13
there are no typing errors, still.....
Please help im desperate!
- 07-05-2007 #6Linux User
- Join Date
- Jun 2007
- Posts
- 318
Post your script as an attachment.
- 07-05-2007 #7Just Joined!
- Join Date
- Jun 2007
- Posts
- 13
Here It Is
Its a copy paste of your reply
- 07-05-2007 #8Just Joined!
- Join Date
- Jun 2007
- Posts
- 13
here it goes
sorry didn't send it in last reply here it is
- 07-05-2007 #9Linux User
- Join Date
- Jun 2007
- Posts
- 318
Don't know what's happening. What the bash manpage says is:
If RANDOM is unset, it loses its special properties, even if it is subsequently
reset.
Sounds like RANDOM is being unset for some reason but I don't know why.
Another way without using RANDOM is this:
ct=`dd bs=200 count=1 < /dev/urandom | tr -cd '[:digit:]' | head -c4`
# Produce a random number from 0 to 9999.
if [ "$ct" = "" ]; then ct=0; fi
# Assume 0 if urandom didn't return any digits.
ct=`echo "scale=0; $ct / 1.38875" | bc`
# Scale down to 7200 seconds (2 hours).
Gotta go. Hope this helps.
- 07-05-2007 #10Just Joined!
- Join Date
- Jun 2007
- Posts
- 13
really strange
This works but im really surprised, the previous commands do work but only in the terminal window and don't inside a bash (.sh) file.
Thanks a lot for all your help this is thing was crucial for me.


Reply With Quote