-
Notifications
You must be signed in to change notification settings - Fork 1
/
report.sh
executable file
·27 lines (26 loc) · 2.07 KB
/
report.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
#!/bin/bash
MONTH=$(date +%B)
HOMEDIR=/home/user
DBUSER=username
DBPASS=password
HOST=hostname
DBNAME=database
SENDTO='[email protected], [email protected]'
cat libraries | while read TOWN
do
echo "Statistics for $TOWN"
echo "Statistics for $TOWN" >> "$HOMEDIR"/"$MONTH"_Reports.csv
echo "Circs by Item Type" >> "$HOMEDIR"/"$MONTH"_Reports.csv
echo "Includes checkouts, renews, and local use circulations" >> "$HOMEDIR"/"$MONTH"_Reports.csv
mysql -u$DBUSER -p$DBPASS -h$HOST -P3306 $DBNAME -e "SELECT items.itype, items.location, count(*) FROM statistics LEFT JOIN items on (items.itemnumber = statistics.itemnumber) LEFT JOIN biblioitems on (biblioitems.biblioitemnumber = items.biblioitemnumber) WHERE statistics.type IN ('issue', 'renew', 'localuse') AND datetime >= concat(date_format(LAST_DAY(now() - interval 1 month),'%Y-%m-'),'01') AND datetime <= LAST_DAY(now() - interval 1 month) AND statistics.branch = '$TOWN' group by items.itype, items.location ORDER BY items.itype, items.location" >> "$HOMEDIR"/"$MONTH"_Reports.csv
echo "-------" >> "$HOMEDIR"/"$MONTH"_Reports.csv
echo "-------" >> "$HOMEDIR"/"$MONTH"_Reports.csv
echo "Circs by Collection Code" >> "$HOMEDIR"/"$MONTH"_Reports.csv
mysql -u$DBUSER -p$DBPASS -h$HOST -P3306 $DBNAME -e "SELECT items.ccode, items.location, count(*) FROM statistics LEFT JOIN items on (items.itemnumber = statistics.itemnumber) LEFT JOIN biblioitems on (biblioitems.biblioitemnumber = items.biblioitemnumber) WHERE statistics.type IN ('issue', 'renew', 'localuse') AND datetime >= concat(date_format(LAST_DAY(now() - interval 1 month),'%Y-%m-'),'01') AND datetime <= LAST_DAY(now() - interval 1 month) AND statistics.branch = '$TOWN' group by items.ccode, items.location ORDER BY items.ccode, items.location" >> "$HOMEDIR"/"$MONTH"_Reports.csv
echo "-------" >> "$HOMEDIR"/"$MONTH"_Reports.csv
echo "-------" >> "$HOMEDIR"/"$MONTH"_Reports.csv
echo "-------" >> "$HOMEDIR"/"$MONTH"_Reports.csv
done
mutt -s "Koha Reports" "$SENDTO" -a "$HOMEDIR"/"$MONTH"_Reports.csv < "$HOMEDIR"/email_template.txt
rm "$HOMEDIR"/"$MONTH"_Reports.csv
echo "Emailed and removed."