File: random-delay

package info (click to toggle)
aptitude-robot 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 520 kB
  • sloc: sh: 704; perl: 536; makefile: 32
file content (16 lines) | stat: -rwxr-xr-x 471 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh

# convert first argument to a number
MAX_DELAY=$(( $1 + 0 ))
[ $MAX_DELAY -gt 0 ] || exit

# delay execution for a random number of seconds
# analogous to the daily cron of apt and cron-apt
if [ "$MAX_DELAY" -gt 0 ] ; then
    if [ -z "$RANDOM" ] ; then
        # A fix for shells that do not have this bash feature.
        RANDOM=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c"1-5")
    fi
    DELAY=$(($RANDOM % $MAX_DELAY))
    sleep $DELAY
fi