[SOLVED] Scripting service monitoring

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

[SOLVED] Scripting service monitoring

Post by simonb256 »

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

Post by uxbod »

#!/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

Post by simonb256 »

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

Post by uxbod »

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

Post by vijendra »

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
Post Reply