[SOLVED] Scripting service monitoring

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
simonb256
Posts: 34
Joined: Fri Sep 12, 2014 11:34 pm

[SOLVED] Scripting service monitoring

Postby simonb256 » Tue Feb 17, 2009 5:46 am

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:
#!/bin/bash

running=`su - zimbra -c "zmcontrol status"|grep Running| awk '{print $1}'|tr "
" " "`

echo ${running[0]}

I get the following:
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.


uxbod
Ambassador
Ambassador
Posts: 7811
Joined: Fri Sep 12, 2014 10:21 pm

[SOLVED] Scripting service monitoring

Postby uxbod » Tue Feb 17, 2009 6:09 am

#!/bin/bash
OIFS=${IFS}

IFS=$'
'
running=($(su - zimbra -c "zmcontrol status"| grep Running | awk '{ print $1 }'))

arrayLen=${#running[@]}

echo "Number of elements : ${arrayLen}"
for (( i=0; i
do

echo "${running[$i]}"

done
IFS=${OIFS}
simonb256
Posts: 34
Joined: Fri Sep 12, 2014 11:34 pm

[SOLVED] Scripting service monitoring

Postby simonb256 » Tue Feb 17, 2009 6:51 am

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
? figures to be honest.
Thanks for the help.
uxbod
Ambassador
Ambassador
Posts: 7811
Joined: Fri Sep 12, 2014 10:21 pm

[SOLVED] Scripting service monitoring

Postby uxbod » Tue Feb 17, 2009 6:58 am

Yes you could, it was more to show the workings :p Glad your sorted now.
vijendra
Posts: 14
Joined: Tue Mar 13, 2018 10:07 pm

Re: [SOLVED] Scripting service monitoring

Postby vijendra » Thu Aug 26, 2021 1:42 pm

uxbod wrote:#!/bin/bash
OIFS=${IFS}

IFS=$'
'
running=($(su - zimbra -c "zmcontrol status"| grep Running | awk '{ print $1 }'))

arrayLen=${#running[@]}

echo "Number of elements : ${arrayLen}"
for (( i=0; i
do

echo "${running[$i]}"

done
IFS=${OIFS}



###################

I used above script but after run it I am getting error like this

Number of elements : 15
test.sh: line 11: unexpected EOF while looking for matching `)'
test.sh: line 18: syntax error: unexpected end of file

Return to “Developers”

Who is online

Users browsing this forum: No registered users and 5 guests