#!/bin/bash # #------------------Change LOG------------------ #v9.5-Added hostname to email notifications #v9.5.1-Removed $(date) from mail string. Mail was processing $(date) as an email address. # #---------------------------------------------- # #Edit crontab as root to modify the schedule of this script. #10,20,30,40,50,00 * * * * /opt/novell/groupwise/gwmail_service_check.sh echo "This script will check to see if $SERVICE1 and $SERVICE2 are running. If one or both are not running this script will start the processe(s). This script will also log the event and email $EMAIL1,$EMAIL2." #Defined variables LOGDATE=$(date +"%m%d%Y") LOG="/var/log/novell/groupwise/gwscript_logs/gw_services_$LOGDATE.log" SERVICE1='gwmta' SERVICE2='grpwise' HOST=gwmail EMAIL1=root EMAIL2=email@domain.com VERSION=v9.5.1 #Check to see if log file exists already, if not create log. if [ -e $LOG ] then echo "Log exists" else touch $LOG ; echo "Log file $LOG created" fi #Write header to log. echo -e "-------------------------$SERVICE1/$SERVICE2 Service Check Log $VERSION-------------------------">>$LOG #Check to see that gwmta process is running. if ps ax | grep -v grep | grep 'gwmta --home /opt/novell/groupwise/' > /dev/null 2>&1 then echo -e $(date) "$SERVICE1 service is running.">>$LOG elif #If service is not running try to restart and send email notification. echo -e $(date) "Sending Email Notice that $SERVICE1 is not running to $EMAIL1,$EMAIL2">>$LOG echo -e $(date) "$SERVICE1 is not running, attempting to restart $SERVICE1 now....">>$LOG echo -e $(date) "$HOST $SERVICE1 is not running! attempting to restart" | mail -s "$HOST $SERVICE1 is down." $EMAIL1,$EMAIL2 /opt/novell/groupwise/agents/bin/gwmta --home /opt/novell/groupwise/ & #for script testing only: /etc/init.d/apache2 start #Import last 15 lines from /var/log/messages to help with troubleshooting. echo -e $(date) "Importing last 15 lines from /var/log/messages to $LOG now.... \r \r From /var/log/messages:">>$LOG tail -15 /var/log/messages>>$LOG echo -e "End /var/log/messages">>$LOG echo -e "\r">>$LOG then #Check to see that service started correctly and send email notification. ps ax | grep -v grep | grep 'gwmta --home /opt/novell/groupwise/' > /dev/null 2>&1 echo -e $(date) "$SERVICE1 started successfully">>$LOG echo -e $(date) "Sending Email Notice that $SERVICE1 restarted successfully $EMAIL1,$EMAIL2">>$LOG echo -e $(date) "$HOST $SERVICE1 has been restarted successfully" | mail -s "$HOST $SERVICE1 restarted" $EMAIL1,$EMAIL2 else #If service failed to start send email notification. echo -e $(date) "$SERVICE1 failed to restart">>$LOG echo -e $(date) "Sending Email Notice for $SERVICE1 restart failed $EMAIL1,$EMAIL2">>$LOG echo -e $(date) "$HOST $SERVICE1 restart failed!" | mail -s "$HOST $SERVICE1 restart failed" $EMAIL1,$EMAIL2 #Import last 15 lines from /var/log/messages to help with troubleshooting. echo -e $(date) "Importing last 15 lines from /var/log/messages to $LOG now.... \r \r From /var/log/messages:">>$LOG tail -15 /var/log/messages>>$LOG echo -e "End /var/log/messages">>$LOG echo -e "\r">>$LOG fi #Check to see that grpwise service is running. if /sbin/service $SERVICE2 status |grep running > /dev/null 2>&1 then echo -e $(date) "$SERVICE2 service is running.">>$LOG echo -e "\r">>$LOG elif #If service is not running try to restart and send email notification. echo -e $(date) "Sending Email Notice for $SERVICE2 is not running to $EMAIL1,$EMAIL2">>$LOG echo -e $(date) "$SERVICE2 is not running, attempting to restart $SERVICE2 now....">>$LOG echo -e $(date) "$HOST $SERVICE2 is not running! attempting to restart" | mail -s "$HOST $SERVICE2 is down." $EMAIL1,$EMAIL2 /etc/init.d/$SERVICE2 start #Import last 15 lines from /var/log/messages to help with troubleshooting. echo -e $(date) "Importing last 15 lines from /var/log/messages to $LOG now.... \r \r From /var/log/messages:">>$LOG tail -15 /var/log/messages>>$LOG echo -e "End /var/log/messages">>$LOG echo -e "\r">>$LOG then #Check to see that service started correctly and send email notification. service $SERVICE2 status |grep running > /dev/null 2>&1 echo -e $(date) "$SERVICE2 started successfully">>$LOG echo -e $(date) "Sending Email Notice for $SERVICE2 restarted successfully $EMAIL1,$EMAIL2">>$LOG echo -e $(date) "$HOST $SERVICE2 has been restarted successfully." | mail -s "$HOST $SERVICE2 restarted" $EMAIL1,$EMAIL2 echo -e "\r">>$LOG else #If service failed to start send email notification. echo -e $(date) "$SERVICE2 Failed to restart">>$LOG echo -e $(date) "Sending Email Notice for $SERVICE2 Failed to restart to $EMAIL1,$EMAIL2">>$LOG echo -e $(date) "$HOST $SERVICE2 failed to restart." | mail -s "$HOST $SERVICE2 failed to restart." $EMAIL1,$EMAIL2 #Import last 15 lines from /var/log/messages to help with troubleshooting. echo -e $(date) "Importing last 15 lines from /var/log/messages to $LOG now.... \r \r From /var/log/messages:">>$LOG tail -15 /var/log/messages>>$LOG echo -e "End /var/log/messages">>$LOG echo -e "\r">>$LOG fi #end script