Skip to content

Instantly share code, notes, and snippets.

@ihipop
Last active February 16, 2017 09:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihipop/acacbd1740d5f5b32ba6 to your computer and use it in GitHub Desktop.
Save ihipop/acacbd1740d5f5b32ba6 to your computer and use it in GitHub Desktop.
delay run Command at random but certain time period without sleep in crontab
#!/bin/bash
#receive command
#you neet atd daemon to do this
cmd="$*"
echo $cmd
[[ $cmd == "" ]] && { echo 'Command Can Not be Empty' ; exit 1; }
command -v at >/dev/null 2>&1 || { echo "I require 'at command' but it's not installed. Aborting." >&2; exit 1; }
#set how many minutes to delay
range=2-350
echo 'sleep ' $(shuf -i 1-60 -n 1) ';' $cmd |at now + $(shuf -i $range -n 1) min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment