Debian Codegraph @

random-delay

raw
1 #!/bin/sh
2
3 # convert first argument to a number
4 MAX_DELAY=$(( $1 + 0 ))
5 [ $MAX_DELAY -gt 0 ] || exit
6
7 # delay execution for a random number of seconds
8 # analogous to the daily cron of apt and cron-apt
9 if [ "$MAX_DELAY" -gt 0 ] ; then
10 if [ -z "$RANDOM" ] ; then
11 # A fix for shells that do not have this bash feature.
12 RANDOM=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c"1-5")
13 fi
14 DELAY=$(($RANDOM % $MAX_DELAY))
15 sleep $DELAY
16 fi