Results 1 to 2 of 2

Thread: Creating reports with CRON

  1. #1
    Join Date
    Dec 2009
    Location
    Michigan
    Posts
    454
    Rep Power
    6

    Default [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 05:13 AM.
    Ben Franklin quote:

    "Those who would give up Essential Liberty to purchase a little Temporary Safety, deserve neither Liberty nor Safety."

  2. #2
    Join Date
    Dec 2009
    Location
    Michigan
    Posts
    454
    Rep Power
    6

    Default

    The fix to this was to change from #!/bin/bash to #!/bin/sh

    Doug
    Ben Franklin quote:

    "Those who would give up Essential Liberty to purchase a little Temporary Safety, deserve neither Liberty nor Safety."

Similar Threads

  1. Creating server entry fails
    By boschika in forum Installation
    Replies: 1
    Last Post: 06-17-2012, 03:31 AM
  2. Cron Daemon error emails each day
    By RJones in forum Installation
    Replies: 0
    Last Post: 09-28-2007, 02:24 AM
  3. admin reports being sent to MTA relay
    By dhickey in forum Administrators
    Replies: 5
    Last Post: 09-14-2007, 01:03 PM
  4. 4.0.4 to 4.5.6 upgrade failed in network edition
    By chenthil in forum Administrators
    Replies: 1
    Last Post: 08-27-2007, 10:36 AM
  5. [SOLVED] Simple backup question...
    By dameron in forum Administrators
    Replies: 3
    Last Post: 08-25-2007, 10:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •