forked from MartineauUK/Chk-WAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cru.sh
46 lines (39 loc) · 896 Bytes
/
cru.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
D="/var/spool/cron/crontabs"
U="$D/cron.update"
F="$D/root"
N="$F.new"
L="/var/lock/cron.lock"
if [ $# -gt 1 -a "$1" = "a" -o "$1" = "d" ]; then
if [ -f $L ];
then
I=$((($$ % 25) + 5))
while ! rm $L 2>/dev/null; do
I=$(($I - 1))
[ $I -lt 0 ] && break
sleep 1
done
fi
ID=$2
grep -v "#$ID#\$" $F >$N 2>/dev/null
if [ "$1" = "a" ]; then
shift
shift
echo -e "$* #$ID#\n" >>$N
fi
mv $N $F
echo root >>$U
echo >$L
exit 0
fi
if [ "$1" = "l" ]; then
cat $F 2>/dev/null
exit 0
fi
cat <<END
Cron Utility
add: cru a <unique id> <"min hour day month week command">
delete: cru d <unique id>
list: cru l
END
exit 0