After a request from a customer to give them a call recording from their Asterisk PBX, we decided to automate things a bit providing them with a daily report on the total incoming & outgoing calls along with the filenames.
Since we saw that the recordings were not archived, we also added such an option, moving files to an external repository for safekeeping.
Cron tab:
# backup daily files on FTP Repository 01 00 * * * rsync -e 'ssh -pxx' -avz /var/spool/asterisk/monitor/ username@xxxxxx.swissns.ch:monitor/ >/dev/null 2>&1 # purge files older than 1 day as new will come 10 00 * * * find /var/spool/asterisk/monitor/ -name '*.gsm' -mtime +1 -delete >/dev/null 2>&1 # send the daily report with email 02 00 * * * /root/daily_report.sh >/dev/null 2>&1
The script is located on /root/daily_report.sh
#!/bin/bash # Create a daily report that will be send at 00:02 with the days' recordings # echo ""> /tmp/report.txt echo "Daily call report" >> /tmp/report.txt echo "" >> /tmp/report.txt echo "Outgoing calls" >> /tmp/report.txt cd /var/spool/asterisk/monitor/ find . -mtime -1 -name 'OUT*' | cut -d '-' -f -1 | uniq -c | sort -n | sed -e 's/\.\/OUT//' |awk '{print $2,":",$1}' >>/tmp/report.txt echo "" >> /tmp/report.txt echo "Incoming calls" >> /tmp/report.txt find . -mtime -1 -name 'g*' | cut -d '-' -f -1 | uniq -c | sort -n | sed -e 's/\.\/g//' |awk '{print $2,":",$1}' >> /tmp/report.txt echo "" >> /tmp/report.txt echo "Full name recordings" >> /tmp/report.txt ls -la * >> /tmp/report.txt mutt -s "Daily recordings report" info@xxxxxxxx.ch,noc@swissns.ch < /tmp/report.txt