#!/bin/bash
EMAIL='[email protected]'
SERVICE='httpd'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "[OK] $SERVICE service running, everything is fine."
else
echo "[!!] $SERVICE is not running."
echo "---> Starting $SERVICE now."
service $SERVICE start > /dev/null
fi
EXITSTATUS=$?
if [[ $EXITSTATUS != 0 ]] ; then
echo "Service status for $SERVICE" >> /tmp/mail.err
echo "**************************************" >> /tmp/mail.err
echo "$SERVICE is down. I can't start it up!" >> /tmp/mail.err
echo "Check log files for more details!" >> /tmp/mail.err
mail -s "Service $SERVICE is down!" $EMAIL < /tmp/mail.err
rm -fr /tmp/mail.err
else
echo "Service status for $SERVICE" >> /tmp/mail.ok
echo "**************************************" >> /tmp/mail.ok
echo "Service $SERVICE was down! Now it's running so everything is fine." >> /tmp/mail.ok
mail -s "Service $SERVICE was down!" $EMAIL < /tmp/mail.ok
rm -fr /tmp/mail.ok
fi
Hvala.