[SOLVED] Creating reports with CRON
There have been times, when we've removed accounts that have been the only subscribers to a distribution list.
When this happens, it's left the distribution list with zero subscribers. I've written a script that will go though all of our lists, count the number of subscribers and email that to the admins.
The script works fine when running it manually, but when running it from CRON, it will only go though the loop, maybe 3 or 4 times, before terminating.
The CRON job entry is running as root, under Ubuntu 8.04LTS 64bit:
Code:
30 21 * * * /usr/local/bin/list_report.sh 2>&1 # Distribution list summary report
Any suggestions would be welcome, script below:
Code:
#!/bin/bash
##############
# Set up paths
##############
PATH=/opt/zimbra/bin:/opt/zimbra/postfix/sbin:/opt/zimbra/openldap/bin:/opt/zimbra/snmp/bin:/opt/zimbra/bdb/bin:/opt/zimbra/openssl/bin:/opt/zimbra/java/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
#####################################
# Export available distribution lists
#####################################
zmprov gadl >/home/doug/reports/lists.tmp
###############
# Sort the list
###############
sort /home/doug/reports/lists.tmp >/home/doug/reports/lists.txt
#################################
# Create report and email headers
#################################
echo "to:support@fakedomain.com" >/home/doug/reports/reports.txt
echo "from:root@fakedomain.com" >>/home/doug/reports/reports.txt
echo "subject:Distribution List Summary" >>/home/doug/reports/reports.txt
echo "Count List name" >>/home/doug/reports/reports.txt
echo "------------------" >>/home/doug/reports/reports.txt
echo "Count List name"
echo "------------------"
############################
# Read sorted list of names
# and get a count of members
############################
while read list_name
do
eval total_lists=`expr $total_lists + 1`
eval list_count=`zmprov gdl "$list_name" |grep -i zimbramailforwardingaddress|wc -l`
echo " $list_count $list_name"
echo " $list_count $list_name" >>/home/doug/reports/reports.txt
done </home/doug/reports/lists.txt
#########################################
# Add total number of lists to the report
#########################################
echo "" >>/home/doug/reports/reports.txt
echo "" >>/home/doug/reports/reports.txt
echo "List count: $total_lists" >>/home/doug/reports/reports.txt
####################
# Send out the email
####################
/opt/zimbra/postfix/sbin/sendmail -t </home/doug/reports/reports.txt Thanks,
Doug
Last edited by lytledd; 12-22-2012 at 04:13 AM.
Ben Franklin quote:
"Those who would give up Essential Liberty to purchase a little Temporary Safety, deserve neither Liberty nor Safety."