Quote:
Originally Posted by linuxmantra
I have written script to check ntpstatus, if ntp service dead it will email to SA else it will email to SA team that script has been executed. I run script everyday at 8 AM via cron. I have 100s of system registered in satellite. Problem here is if script is executed, in 100s of system and no ntp service issue then 100s of email will comes up stating "script executed". I want only one email not 100s. here is my code. Any suggestion how can I modify my script.
Code:
#!/bin/bash
#
# NTP service check script
#
MAILTO="sa@exmaple.com"
/sbin/service ntpd status
OUT=$?
if [ $OUT -ne 0 ];
then
echo "Please check, ntp service is dead on $(hostname)" | mailx -s "NTP service dead in $(hostname)" $MAILTO
else
echo "No issue. ntp service check script executed on $(date)" | mailx -s "ntpstatus script executed" $MAILTO
fi
|
Please use CODE tags.
And if you're saying that you have this script on 100 machines now...you're
STILL going to get 100 emails..whether they come in at exactly the same second or not won't matter.
If it was me, I'd write a script using snmpwalk, to cycle through the running processes on the systems listed in a file/database/whatever, and check for the process. Build a single email from that, and have it run one ONE system, to send out one email. You could even use passwordless-ssh and cycle through a simple command (such as "service check ntpd" or "ps -ef | grep ntp"), and parse the results to build that email.