Skip to content

Commit

Permalink
A hook that randomizes the system crontab
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkiousis authored and ramereth committed Apr 11, 2015
1 parent 6a1f59b commit 60f598b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions example/hooks/cron_randomize
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

#
# Copyright (C) 2011 Greek Research and Technology Network
#

set -e

. common.sh

debug set -x

trap cleanup EXIT

n=$RANDOM
min=$(( n %= 30 ))

echo "SHELL=/bin/sh" > ${TARGET}/etc/crontab
echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> ${TARGET}/etc/crontab
printf "\n" >> ${TARGET}/etc/crontab
echo "# m h dom mon dow user command" >> ${TARGET}/etc/crontab
echo "$min * * * * root cd / && run-parts --report cron.hourly" >> ${TARGET}/etc/crontab
echo "$((min + 7)) 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report cron.daily )" >> ${TARGET}/etc/crontab
echo "$((min + 13)) 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report cron.weekly )" >> ${TARGET}/etc/crontab
echo "$((min + 24)) 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report cron.monthly )" >> ${TARGET}/etc/crontab

trap - EXIT
exit 0

0 comments on commit 60f598b

Please sign in to comment.