sorry to hear that it did not work out of the box for you. why is it that things that work well on Ubuntu just don't work the same on RH.
Could you maybe send me your version info for:
bash, su an your env setup e.g. /etc/profile, /etc/bash.bashrc, and ~/.bashrc. or maybe you want to migrate your system to Ubuntu? :D
Fun aside.
I changed the script's sudo execution to su and now pack the zmcontrol strings into a $CMD variable and then pass it onto su -
And from your output I see that there is a problem with the with the way the $CMD construct is being passed onto su.... Nothing wild!
On lines 148 to 152 is this $CMD construct, which I think you should have a look at maybe there is a quote sign in the $CMD variable which is not liked by su or zmcontrol
here is a script to diagnose what is going wrong in the variable construct and to test the stop and start logic in the script. You just have to uncomment the section you want to test.
#!/bin/bash
ZM_HOME=/opt/zimbra/
ZM_USER=`ps -ef | grep "$ZM_HOME" | grep "java" | grep -v "zmmailboxdmgr" | awk '{print $1}' | head -n 1`
if [ -z $ZM_USER ]
then
echo "Unable to determan the zimbra user"
cat $LOG | mail -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
exit 1
elif [ $ZM_USER = "root" ]
then
echo "Zimbra user should never be root! I'll die now..."
# send email....
cat $LOG | mail -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
exit 1
fi
# Command short form
ZIM_STOP="$ZM_USER -c $ZM_HOME"bin/zmcontrol" shutdown"
ZIM_START="$ZM_USER -c $ZM_HOME"bin/zmcontrol" start"
ZIM_STATUS="$ZM_USER -c $ZM_HOME"bin/zmcontrol" status"
ZIM_STAT_START="$ZM_USER -c $ZM_HOME"bin/zmstatctl" start"
ZIM_STAT_STOP="$ZM_USER -c $ZM_HOME"bin/zmstatctl" stop"
echo
echo $ZIM_STOP
echo
echo $ZIM_START
echo
echo $ZIM_STATUS
echo
echo $ZIM_STAT_START
echo
echo $ZIM_STAT_STOP
echo
########## Stopping Zimbra
# echo "Stopping the Zimbra server"
# sleep 2 && sync
# su - $ZIM_STOP
# if [ "$?" -eq "1" ]
# then
# echo "zmcontrol shutdown had an error!"
# # send email....
# cat $LOG | mail -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
# else
# echo
# echo "Zimbra server has stopped "
# fi
#
#...................................................................................
# echo
########## Starting the Zimbra server again
# su - $ZIM_START
# if [ "$?" -ne "0" ]
# then
# echo "There was an error starting Zimbra!"
# # send email....
# cat $LOG | mail -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
# else
# echo
# echo "Zimbra has started"
# fi
#
# sleep 15
#...................................................................................
######### quick hack to start the stats component
# # On my system I have 7 pid files whe all is running well, you might have less depending on your config
# SPIDS=`ls -A -1 $STATPIDBASE | wc -l`
# if [ "$SPIDS" != "7" ]
# then
# echo "I am expecting 7 pids for Stats, rebooting Stats subsystem!"
# su - $ZIM_STAT_STOP
# if [ "$?" -ne "0" ]
# then
# echo "Stopping stats failed!"
# # send email....
# cat $LOG | mail -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
# else
# echo "Stats have been stopped"
# fi
#
# sleep 2
# su - $ZIM_STAT_START
# if [ "$?" -ne "0" ]
# then
# echo "Starting stats failed!"
# # send email....
# cat $LOG | mail -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
# else
# echo "Stats started..."
# fi
# else
# echo "Stats seems to be running fine..."
# fi
#
# # Status Check to see that is running
# sleep 2
# STATUS=`su - $ZIM_STATUS | grep Stopped`
# if [ "$STATUS" ]
# then
# echo $STATUS
# # send email....
# cat $LOG | mail -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
# fi
You can also send my a private message then we can try diagnose this via skype.... I would really like this scrip to be more compatible with other distros and to work without changing code in the logic section of the script.
Cheers heinzg