I have a simple bash script to monitor the status of a service.
Script control
All working fin except init script start service when script run on a cron jobs. If execute manually this script work fine all.
#!/bin/bash
estado=$(/etc/init.d/open-xchange status)
echo $estado
if [ "$estado" != "Checking for Open-Xchange: running." ]; then
hora=$(date +%F-%T)
tail -n 1000 /var/log/open-xchange/open-xchange.log.0 > /tmp/open-xchange.log.$hora
cat /tmp/open-xchange.log.$hora |mail -s "Reinicio en OX $hora" [email protected]
rm -f /tmp/open-xchange.log.$hora
echo $hora >> /root/caidas-ox.txt
/etc/init.d/open-xchange start # The problem. This command not work when scripts its executed form crond
sleep 10
/opt/open-xchange/sbin/showruntimestats -d 'java.util.logging:type=Logging!setLoggerLevel!!ALL!'
fi
All commands on conditional working fine on shell and with cron, except /etc/init.d/open-xchange start (try using /bin/bash /etc/init.d/open-xchange start, service open-xchange start,...)
/opt/open-xchange/lib/oxfunctions.sh: line 109: start-stop-daemon: command not found
start option is calling command start-stop-daemon
to start the service, any one of 3 options will solve your issue:
export PATH=$PATH:/path/to/start-stop-daemon/directory
to your
scriptsource ~/.bash_profile
or source ~/.bashrc
to your script