Contents of /trunk/fcron/run-crons
Parent Directory | Revision Log
Revision 144 -
(show annotations)
(download)
Tue May 8 20:06:05 2007 UTC (17 years, 4 months ago) by niro
File size: 2520 byte(s)
Tue May 8 20:06:05 2007 UTC (17 years, 4 months ago) by niro
File size: 2520 byte(s)
-import
1 | #!/bin/bash |
2 | |
3 | # 06 May 2004; Aron Griffis <agriffis@gentoo.org> run-crons: |
4 | # Make the locking actually work. The old code was racy. |
5 | # Thanks to Mathias Gumz in bug 45155 for some cleanups. |
6 | # |
7 | # 23 Jun 2002; Jon Nelson <jnelson@gentoo.org> run-crons: |
8 | # fixed a race condition, where cron jobs and run-crons wanted to |
9 | # delete touch files |
10 | # |
11 | # 20 Apr 2002; Thilo Bangert <bangert@gentoo.org> run-crons: |
12 | # moved lastrun directory to /var/spool/cron/lastrun |
13 | # |
14 | # Author: Achim Gottinger <achim@gentoo.org> |
15 | # |
16 | # Mostly copied from SuSE |
17 | # |
18 | # this script looks into /etc/cron.[hourly|daily|weekly|monthly] |
19 | # for scripts to be executed. The info about last run is stored in |
20 | # /var/spool/cron/lastrun |
21 | |
22 | LOCKDIR=/var/spool/cron/lastrun |
23 | LOCKFILE=${LOCKDIR}/lock |
24 | |
25 | mkdir -p ${LOCKDIR} |
26 | |
27 | # Make sure we're not running multiple instances at once. |
28 | # Try twice to lock, otherwise give up. |
29 | for ((i = 0; i < 2; i = i + 1)); do |
30 | ln -sn $$ ${LOCKFILE} 2>/dev/null |
31 | if [[ $? != 0 ]]; then |
32 | # lock failed, check for a running process. |
33 | # handle both old- and new-style locking. |
34 | cronpid=$(readlink ${LOCKFILE} 2>/dev/null || |
35 | cat ${LOCKFILE} 2>/dev/null) |
36 | if [[ $? == 0 ]]; then |
37 | if kill -0 ${cronpid} 2>/dev/null; then |
38 | # whoa, another process is really running |
39 | exit 0 |
40 | else |
41 | rm -f ${LOCKFILE} |
42 | fi |
43 | fi |
44 | fi |
45 | done |
46 | |
47 | # Set a trap to remove the lockfile when we're finished |
48 | trap "rm -f ${LOCKFILE}" 0 1 2 3 15 |
49 | |
50 | |
51 | for BASE in hourly daily weekly monthly |
52 | do |
53 | CRONDIR=/etc/cron.${BASE} |
54 | |
55 | test -d $CRONDIR || continue |
56 | |
57 | if [ -e ${LOCKDIR}/cron.$BASE ] |
58 | then |
59 | case $BASE in |
60 | hourly) |
61 | #>= 1 hour, 5 min -=> +65 min |
62 | TIME="-cmin +65" ;; |
63 | daily) |
64 | #>= 1 day, 5 min -=> +1445 min |
65 | TIME="-cmin +1445" ;; |
66 | weekly) |
67 | #>= 1 week, 5 min -=> +10085 min |
68 | TIME="-cmin +10085" ;; |
69 | monthly) |
70 | #>= 31 days, 5 min -=> +44645 min |
71 | TIME="-cmin +44645" ;; |
72 | esac |
73 | find ${LOCKDIR} -name cron.$BASE $TIME -exec rm {} \; |
74 | fi |
75 | |
76 | # if there is no touch file, make one then run the scripts |
77 | if [ ! -e ${LOCKDIR}/cron.$BASE ] |
78 | then |
79 | touch ${LOCKDIR}/cron.$BASE |
80 | |
81 | set +e |
82 | for SCRIPT in $CRONDIR/* |
83 | do |
84 | if [[ -x $SCRIPT && ! -d $SCRIPT ]]; then |
85 | $SCRIPT |
86 | fi |
87 | done |
88 | fi |
89 | done |
90 | |
91 | # Clean out bogus cron.$BASE files with future times |
92 | touch ${LOCKDIR} |
93 | find ${LOCKDIR} -newer ${LOCKDIR} -exec /bin/rm -f {} \; |