-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcron-rummy
120 lines (94 loc) · 2.47 KB
/
cron-rummy
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
#
# Synopsis:
# Cron job to "get" blobs with unknown facts and log to spool/rummy.rdr
# Usage:
# SETSPACE_ROOT=/opt/local/jmscott/jmsdesk/setspace
# LOG=/opt/local/jmscott/jmsdesk/setspace/log/cron-rummy
#
# * * * * * $SETSPACE_ROOT/sbin/cron-rummy '-1 hour' >>$LOG-min.log 2>&1
# 24 * * * * $SETSPACE_ROOT/sbin/cron-rummy '1 week' >>$LOG-hr.log 2>&1
# Exit Status:
# 0 ok
# 1 failed
# Note:
# A nice addition would be to display/log the discover time of each
# gotten blob.
#
PROG=cron-rummy
log()
{
echo "$(date +'%Y/%m/%d %H:%M:%S'): #$$: $@"
}
die()
{
log "ERROR: $@" >&2
exit 1
}
leave()
{
rm -f $RUN $TMP_RUMMY
log 'good bye, cruel world'
exit
}
trap leave EXIT
log 'hello, world'
test $# = 0 || die 'wrong number of arguments'
test -n "$SETSPACE_ROOT" || die 'env var not defined: SETSPACE_ROOT'
log "SETSPACE_ROOT=$SETSPACE_ROOT"
cd $SETSPACE_ROOT || die "cd $SETSPACE_ROOT failed"
. etc/profile
unset BLOBIO_GET_SERVICE
log "BLOBIO_ROOT=$BLOBIO_ROOT"
log "BLOBIO_SERVICE=$BLOBIO_SERVICE"
test -d spool || die "directory not found: $(pwd)/spool"
SPOOL=spool/rummy.rdr
test -d run || die "directory not found: $(pwd)/run"
RUN=run/$PROG.pid
# only one rummy running
if [ -e $RUN ]; then
log "WARN: run pid exists: $RUN"
PID=$(cat $RUN)
log "WARN: is another $PROG running with pid #$PID ?"
log "WARN: if no process #$PID is running then remove $RUN"
exit
fi
echo $$ >$RUN || die "echo >$RUN failed: exit status=$?"
log "TMPDIR=$TMPDIR"
TMP_RUMMY=${TMPDIR:=/tmp}/$PROG-$$.udig
NOW=$(RFC3339Nano)
log "now: $NOW"
# find the blobs with known unknowns ..
rummy >$TMP_RUMMY || die "rummy failed: exit status=$?"
RC=$(wc -l $TMP_RUMMY | awk '{print $1}')
log "total blob count: $RC"
# track blobio ok/no chat history count in global array
declare -a ok_no
ok_no[0]=0;
ok_no[1]=0;
# "get" the blobs one at a time and record status in spool/rummy.rdr
while read SCH U; do
# fetch the blob from the service
blobio get --udig $U --service $BLOBIO_SERVICE --output-path /dev/null
STATUS=$?
case $STATUS in
0)
log "<$U $SCH"
ok_no[0]=$(expr ${ok_no[0]} + 1)
CHAT_HISTORY=ok
;;
1)
log "?$U $SCH"
ok_no[1]=$(expr ${ok_no[1]} + 1)
CHAT_HISTORY=no
;;
*)
die "blobio get $U failed: exit status=$STATUS"
;;
esac
# record the detail of the rummied blob into spool/rummy.rdr
echo "$NOW $U $SCH $CHAT_HISTORY" >>$SPOOL ||
die "echo >$SPOOL failed: exit status=$?"
done <$TMP_RUMMY
log "ok count: ${ok_no[0]}"
log "no count: ${ok_no[1]}"