Thanks to this forum and scripting Gurus, I have written my first script. The script basically runs as a cronjob every 15 minutes, checks to see if syslogd is running and logging messages to the message file. If the file size doesn't change, it assumes syslogd is not running and stops and starts it. If after 75 seconds it can't start it, it emails a message. Below is the script. What I need help with is:
1. How can I check to see if syslogd process is running twice and if so, kill those processes? I have seen where syslogd will not start when 2 processes are spawned. I know the ps command etc but don't know how to put it in this script.
2. The mail message doesn't work. I looked at the man page but still can't figure it out. I would like to put a lot of text in the message, basically a msg to tell them to call 2 people and provide the phone numbers etc.
3. I would appreciate any suggestions on how to improve this script. I intend to start writing alot of them and do not know the "better" or correct way of doing things.
4. When this script runs, is it hogging all the cpu time? When a process sleeps, does the system run other jobs?
Any help with the above questions is greatly appreciated!
#!/bin/ksh
#
# Script to check if the syslogd process is running and logging
# messages to the /var/adm/message file. A change in the file size of the
# message file indicates that logging is being performed.
# This script runs as a cron job every 15 minutes.
#
count=0
# Get initial filesize
first_time=`ls -al /var/adm/messages | awk '{print $5}'`
# Wait 15 secs. If file size hasn't changed,
# assume syslogd is not running. Stop and start it.
#
while [ count -le "4" ]
do
sleep 15 #wait 15 secs
next_time=`ls -al /var/adm/messages | awk '{print $5}'`
if [ "$first_time" == "$next_time" ]
then
count=$((count+1))
/etc/init.d/syslog stop # stop syslogd
/etc/init.d/syslog start # start syslogd
else
count=0 # reset count for next time.
exit 0 # get out of this script. Everything is ok.
fi
done
#
# If we get here, we have problems. Can't start syslogd.
if [ $count -gt "4" ]
then
mailx -s "SYSLOG SERVER NEEDS IMMEDIATE ATTENTION!!!!" someone@this-don't-work.com
exit 77
else
exit 88
fi
1. How can I check to see if syslogd process is running twice and if so, kill those processes? I have seen where syslogd will not start when 2 processes are spawned. I know the ps command etc but don't know how to put it in this script.
2. The mail message doesn't work. I looked at the man page but still can't figure it out. I would like to put a lot of text in the message, basically a msg to tell them to call 2 people and provide the phone numbers etc.
3. I would appreciate any suggestions on how to improve this script. I intend to start writing alot of them and do not know the "better" or correct way of doing things.
4. When this script runs, is it hogging all the cpu time? When a process sleeps, does the system run other jobs?
Any help with the above questions is greatly appreciated!
#!/bin/ksh
#
# Script to check if the syslogd process is running and logging
# messages to the /var/adm/message file. A change in the file size of the
# message file indicates that logging is being performed.
# This script runs as a cron job every 15 minutes.
#
count=0
# Get initial filesize
first_time=`ls -al /var/adm/messages | awk '{print $5}'`
# Wait 15 secs. If file size hasn't changed,
# assume syslogd is not running. Stop and start it.
#
while [ count -le "4" ]
do
sleep 15 #wait 15 secs
next_time=`ls -al /var/adm/messages | awk '{print $5}'`
if [ "$first_time" == "$next_time" ]
then
count=$((count+1))
/etc/init.d/syslog stop # stop syslogd
/etc/init.d/syslog start # start syslogd
else
count=0 # reset count for next time.
exit 0 # get out of this script. Everything is ok.
fi
done
#
# If we get here, we have problems. Can't start syslogd.
if [ $count -gt "4" ]
then
mailx -s "SYSLOG SERVER NEEDS IMMEDIATE ATTENTION!!!!" someone@this-don't-work.com
exit 77
else
exit 88
fi