Results 1 to 4 of 4

Thread: [SOLVED] Scripting service monitoring

  1. #1
    simonb256 is offline Active Member
    Join Date
    Jun 2008
    Location
    Wolverhampton, UK.
    Posts
    34
    Rep Power
    7

    Default [SOLVED] Scripting service monitoring

    Hi all,

    I'm currently attempting to script something that checks 'zmcontrol status' and attempts to start services if they have failed (it will be growing beyond that, but this is the basic need).

    At present I run 'zmcontrol status' and strip the output down to just a list of running services. I then try to store this in an array. However for some reason my array only ever seems to contain one item (the entire list).

    For instance if I run:

    Code:
    #!/bin/bash
    running=`su - zimbra -c "zmcontrol status"|grep Running| awk '{print $1}'|tr "\n" " "`
    echo ${running[0]}
    I get the following:

    Code:
    antispam antivirus ldap logger mailbox mta snmp spell stats
    Could someone kindly point out what I am missing? As I've been scratching my head with this for a while now.

  2. #2
    uxbod's Avatar
    uxbod is offline Moderator
    Join Date
    Nov 2006
    Location
    UK
    Posts
    8,017
    Rep Power
    24

    Default

    Code:
    #!/bin/bash
    
    OIFS=${IFS}
    IFS=$'\n'
    
    running=($(su - zimbra -c "zmcontrol status"| grep Running | awk '{ print $1 }'))
    arrayLen=${#running[@]}
    echo "Number of elements : ${arrayLen}"
    
    for (( i=0; i<${arrayLen}; i++ ));
    do
      echo "${running[$i]}"
    done
    
    IFS=${OIFS}

  3. #3
    simonb256 is offline Active Member
    Join Date
    Jun 2008
    Location
    Wolverhampton, UK.
    Posts
    34
    Rep Power
    7

    Default

    Thanks kindly for that.

    So my suspicions were correct that it was IFS?

    I could of just left it at being one line each and set the IFS to be \n? figures to be honest.

    Thanks for the help.

  4. #4
    uxbod's Avatar
    uxbod is offline Moderator
    Join Date
    Nov 2006
    Location
    UK
    Posts
    8,017
    Rep Power
    24

    Default

    Yes you could, it was more to show the workings Glad your sorted now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Zimbra .pids / service monitoring
    By bin2hex in forum Administrators
    Replies: 24
    Last Post: 04-03-2010, 09:12 PM
  2. MTA service stopping and 1m later starting again?
    By ArcaneMagus in forum Administrators
    Replies: 5
    Last Post: 03-23-2010, 08:43 AM
  3. Replies: 5
    Last Post: 05-28-2009, 12:53 AM
  4. Zimbra Server very slow - Too many SMTP connections
    By pc-nico in forum Administrators
    Replies: 23
    Last Post: 06-05-2008, 05:12 AM
  5. Replies: 20
    Last Post: 03-18-2008, 05:37 AM

Posting Permissions

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