Ruby script to delay execution of a command (intended for @reboot crontab)
# Start after delay
#
# Delay specifications must be one of Xs (secs), Xm (mins), Xh (hours)
case ARGV[0]
when /(\d+)s/
@delay = $1.to_i
when /(\d+)m/
@delay = 60 * $1.to_i
when /(\d+)h/
@delay = 3600 * $1.to_i
else
raise "Incorrect delay specification"
end
# A random factor of up to 10% will be added to any given delay
@rf = ( @delay * 0.1 ).to_i
@delay += rand( @rf )
sleep( @delay )
# Join up remaining arguments to form the command to be executed
ARGV.slice!( 0 )
@command = ARGV.join( ' ' )
exec( @command )