-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron-style.sh
50 lines (44 loc) · 1.31 KB
/
cron-style.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
47
48
49
50
#!/bin/bash
# m h dom mon dow
sched="41 18 * * 3"
read m_when h_when dom_when mon_when dow_when <<< $sched
echo "$m_when"
echo "$mon_when"
delay=0
gone=0
while true; do
m_now=$(date +%M)
h_now=$(date +%H)
dom_now=$(date +%d)
mon_now=$(date +%m)
dow_now=$(date +%u)
go=0
if [ "$m_when" = "*" -o "$m_when" = "$m_now" ]; then
go=$[$go+1]
fi
if [ "$h_when" = "*" -o "$h_when" = "$h_now" ]; then
go=$[$go+1]
fi
if [ "$dom_when" = "*" -o "$dom_when" = "$dom_now" ]; then
go=$[$go+1]
fi
if [ "$mon_when" = "*" -o "$mon_when" = "$mon_now" ]; then
go=$[$go+1]
fi
if [ "$dow_when" = "*" -o "$dow_when" = "$dow_now" ]; then
go=$[$go+1]
fi
if [ $go -eq 5 ]; then
if [ $delay -eq 0 ]; then
replay=$[$(date +%s)+61]
echo "ok, let's go"
delay=1
fi
if [ $(date +%s) -gt $replay ]; then
delay=0
fi
else
echo "nothing to do: when: $m_when $h_when $dom_when $mon_when $dow_when . now: $m_now $h_now $dom_now $mon_now $dow_now"
fi
sleep 5
done