i made a really simple script to ensure my important services are active.
#!/bin/bash
services=(apache2 sendmail mysql)
for service in "${services[@]}"
do
if [[ $(service $service status | grep running) ]]; then
echo $service " is active" >> /home/user/logging.txt
else
echo "!!!!" $service " is not active!!!!" >> /home/user/logging.txt
fi
done
When i run the script manually, everything works fine, active services get logged as active and inactive services logged as inactive.
For automating the script i made an entry in crontab:
0 10 * * * /usr/bin/service-check
The script runs but the output generated in the logging file is not correct!
The output in the loggingfile says for every Service:
!!! servicename is not active !!!
i repeated the steps several times same result over again...
Output of the logging file:
!!!! apache2 is not active!!!!
!!!! sendmail is not active!!!!
!!!! mysql is not active!!!!
apache2 is active
sendmail is active
mysql is active
The first three lines are from crontab, the last three from manual start... This really grind my gears and i can't figure out whats wrong... any idea?
$(service $service status | grep running)
into the log? ;-) – Rinzwind Oct 05 '17 at 10:27