Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-17-2009, 04:46 AM
Active Member
 
Posts: 34
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.
Reply With Quote
  #2 (permalink)  
Old 02-17-2009, 05:09 AM
Moderator
 
Posts: 7,911
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}
__________________
Reply With Quote
  #3 (permalink)  
Old 02-17-2009, 05:51 AM
Active Member
 
Posts: 34
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.
Reply With Quote
  #4 (permalink)  
Old 02-17-2009, 05:58 AM
Moderator
 
Posts: 7,911
Default

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.