summaryrefslogtreecommitdiff
path: root/bin/billco-upload
blob: 3a02ec8bbb34a74dee790bbcf9a8f062ead4d2a4 (plain)
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
#!/bin/sh

AGENTNUMS="1 2 3 5 8 9 10"

date=`date +"%Y%m%d"`
dir="/usr/local/etc/freeside/export.DBI:Pg:dbname=freeside/cust_bill"
lock=".billco-upload.lock"
cd "$dir"

failed_mutex()
{
  echo "billco-upload already running; exiting"
  exit 1
}

#acquire mutex
[ -f $lock ] && {
  failed_mutex
} || {
  echo $$ > $lock
  [ $(cat $lock 2>/dev/null) -eq $$ ] || failed_mutex
}

for AGENTNUM in $AGENTNUMS; do

  for a in header detail; do
    mv agentnum$AGENTNUM-$a.csv agentnum$AGENTNUM-$date-$a.csv
  done

  zip agentnum$AGENTNUM-$date.zip agentnum$AGENTNUM-$date-header.csv agentnum$AGENTNUM-$date-detail.csv

# Remove if trying to find problems with billco upload files
  rm *$AGENTNUM-$date*.csv

  echo $dir/agentnum$AGENTNUM-$date.zip

done

#release mutex
rm -f $lock