Skip to content

Commit 60f598b

Browse files
alexkiousisramereth
authored andcommitted
A hook that randomizes the system crontab
1 parent 6a1f59b commit 60f598b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

example/hooks/cron_randomize

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (C) 2011 Greek Research and Technology Network
5+
#
6+
7+
set -e
8+
9+
. common.sh
10+
11+
debug set -x
12+
13+
trap cleanup EXIT
14+
15+
n=$RANDOM
16+
min=$(( n %= 30 ))
17+
18+
echo "SHELL=/bin/sh" > ${TARGET}/etc/crontab
19+
echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> ${TARGET}/etc/crontab
20+
printf "\n" >> ${TARGET}/etc/crontab
21+
echo "# m h dom mon dow user command" >> ${TARGET}/etc/crontab
22+
echo "$min * * * * root cd / && run-parts --report cron.hourly" >> ${TARGET}/etc/crontab
23+
echo "$((min + 7)) 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report cron.daily )" >> ${TARGET}/etc/crontab
24+
echo "$((min + 13)) 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report cron.weekly )" >> ${TARGET}/etc/crontab
25+
echo "$((min + 24)) 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report cron.monthly )" >> ${TARGET}/etc/crontab
26+
27+
trap - EXIT
28+
exit 0

0 commit comments

Comments
 (0)