add mutex and commit changes found on installed system
[freeside.git] / bin / billco-upload
1 #!/bin/sh
2
3 AGENTNUMS="1 2 3 5 8 9 10"
4
5 date=`date +"%Y%m%d"`
6 dir="/usr/local/etc/freeside/export.DBI:Pg:dbname=freeside/cust_bill"
7 lock=".billco-upload.lock"
8 cd "$dir"
9
10 failed_mutex()
11 {
12   echo "billco-upload already running; exiting"
13   exit 1
14 }
15
16 #acquire mutex
17 [ -f $lock ] && {
18   failed_mutex
19 } || {
20   echo $$ > $lock
21   [ $(cat $lock 2>/dev/null) -eq $$ ] || failed_mutex
22 }
23
24 for AGENTNUM in $AGENTNUMS; do
25
26   for a in header detail; do
27     mv agentnum$AGENTNUM-$a.csv agentnum$AGENTNUM-$date-$a.csv
28   done
29
30   zip agentnum$AGENTNUM-$date.zip agentnum$AGENTNUM-$date-header.csv agentnum$AGENTNUM-$date-detail.csv
31
32 # Remove if trying to find problems with billco upload files
33   rm *$AGENTNUM-$date*.csv
34
35   echo $dir/agentnum$AGENTNUM-$date.zip
36
37 done
38
39 #release mutex
40 rm -f $lock