#! /bin/sh # # condo fees: 1st # MSF contribution: 15th # ACCDIR=/home/mouse/acc PATH=$ACCDIR/bin:/bin:/usr/bin export PATH # cd $ACCDIR lastdonefile=data/.cronlast mousecf=data/mouse/config.db mailer=/usr/bin/mail # # on 7th, run for the 15th; on the 26st, run for the 1st of the next month. # umask 002 pid=$$ mousedb=`conf -p db -config $mousecf` if sslock $mousedb $pid; then :; else exit 1; fi (( echo PATH="$PATH" last=`cat $lastdonefile` now=`ndate` accounts="" #echo \$last before loop: $last 1>&2 while [ $last -le $now ] do echo \$last in loop: $last 1>&2 case $last in *07) date=${last%??}15 ;; *26) date=`ndate $(( ${last%??}00 + 101 ))` ;; *) date='' ;; esac # -------- condo fees --------- case $date in *01) echo $date:$now:c:out.bas.res.condo fees:tca::xxx:CAD >> $mousedb accounts="$accounts Mtca:500" # echo accounts now \""$accounts"\" 1>&2 ;; esac # -------- MSF contribution --------- case $date in *15) echo $date:$now:c:out.lux.charity.msf:mastercard::xxx:CAD >> $mousedb ;; esac # -------- end of items --------- last=`ndate -add 1 $last` done #echo \$last after loop: $last 1>&2 echo $last > $lastdonefile umask 077 #echo accounts after loop \""$accounts"\" 1>&2 case "$accounts" in "") ;; *) echo check automated accounting entries | $mailer mouse ( echo `echo $accounts | tr ' ' ' ' | sort | uniq` | tr ' ' : echo Mouse cat $mousedb | MDB_CONFIG_DB=$mousecf totals -raw ) | awk -F: 'NR==1 { for (i=1;i<=NF;i+=2) { min[$i] = $(i+1); a[$i] = 1; } next; } NF==1 { tag = $1; } { acc = substr(tag,1,1) $1; if ((a[acc] == 1) && ($3 < min[acc])) { print tag "-" $0; } }' > /tmp/$$.log if [ -s /tmp/$$.log ]; then ( for i in Mouse:$mousecf do j=`echo $i | sed -e 's/^[^:]*://'` k=`echo $i | sed -e 's/:.*//'` if egrep \^$k < /tmp/$$.log > /tmp/$$.grep; then echo For $k\'s database: MDB_CONFIG_DB=$j totals -fmt < /tmp/$$.grep | sed -e 's/^'$k'-/ /' fi rm -f /tmp/$$.grep done ) | $mailer -s 'acc cronjob warning' mouse fi ;; esac ) 2>&1 ) > /dev/null # | $mailer -s 'acc cronjob debug' mouse rm -f /tmp/$$.log /tmp/$$.fmt ssunlock $mousedb