Wednesday, October 7, 2015

Random sleep duration in bash

I needed to insert random data into a test database, but I it need to be a 1-10 second random sleep/pause between in each insert.

I came across this.

sleep $[ ( $RANDOM % 10 )  + 1 ]s
(Thanks  http://blog.buberel.org/2010/07/howto-random-sleep-duration-in-bash.html)

If you want to see  the command I was using:

while true ; do mysql bctest -e "INSERT INTO random_lookup(lookup_value) SELECT LPAD( '', 100, MD5( CAST( RAND() AS CHAR ) ) ) FROM random_lookup LIMIT 100000;"; sleep $[ ( $RANDOM % 10 )  + 1 ]s; done

HTH

Brent

No comments:

Post a Comment