crontab stuff

Create a crontab entry with random minute/hour. (replace /bin/true with the wanted command!)

Every day:

m=$(( RANDOM % 60 )); h=$(( RANDOM % 24 )); cmd="/bin/true"
echo "$m $h * * * root $cmd" | tee -a /etc/crontab

Once per week:

m=$(( RANDOM % 60 )); h=$(( RANDOM % 24 )); d=$(( RANDOM % 7 )); cmd="/bin/true"
echo "$m $h * * $d root $cmd" | tee -a /etc/crontab

Check that the latest edit to crontab is accepted:

grep crontab /var/log/syslog

List crontab entries sorted by frequency and time

egrep '^[0-9\s\*]+' /etc/crontab | sort -k4,4n -k3,3n -k5,5 -k2,2n -k1,1n

egrep '^[0-9\s\*]+' /etc/crontab | sort -k4,4n -k3,3n -k5,5 -k2,2n -k1,1n | perl -nle '@cron=split(/\s+/,$_,7); printf "%5s "x5 . "%10s   %s\n", @cron'