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.
[SOLVED] Scripting service monitoring
[SOLVED] Scripting service monitoring
#!/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}
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}
[SOLVED] Scripting service monitoring
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.
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.
[SOLVED] Scripting service monitoring
Yes you could, it was more to show the workings :p Glad your sorted now.
Re: [SOLVED] Scripting service monitoring
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