LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script via Satellite (https://www.linuxquestions.org/questions/linux-newbie-8/script-via-satellite-4175576319/)

linuxmantra 03-31-2016 11:45 AM

Script via Satellite
 
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.

#!/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

TB0ne 03-31-2016 12:00 PM

Quote:

Originally Posted by linuxmantra (Post 5524148)
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.

malekmustaq 03-31-2016 12:02 PM

1. Change that MAILTO to a single flag packet addressed to your admin system IP; this way you will know which among the 100s reported a success or fail flag; or you can delimit reporting only those that failed.
2. Then you only run a local script to read the control record to identify which clients failed.


All times are GMT -5. The time now is 09:59 AM.