<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need Scripting Help - Script to send email if server goes down in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603283#M34648</link>
    <description>Laurie,&lt;BR /&gt;&lt;BR /&gt;Try this page, you will be able to customize this software and it will provide you with alot of future functionality.&lt;BR /&gt;&lt;BR /&gt;Enjoy,&lt;BR /&gt;Craig&lt;BR /&gt;&lt;A href="http://www.cert.dfn.de/eng/logsurf/" target="_blank"&gt;http://www.cert.dfn.de/eng/logsurf/&lt;/A&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 29 Oct 2001 16:10:38 GMT</pubDate>
    <dc:creator>Craig Rants</dc:creator>
    <dc:date>2001-10-29T16:10:38Z</dc:date>
    <item>
      <title>Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603277#M34642</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;I have a (borne shell) script in cron that runs once a day and it monitors my global syslog.  All my servers send a copy of their&lt;BR /&gt;syslog to this one server call GOAT.&lt;BR /&gt;&lt;BR /&gt;It works great, I get an email and a pager email.  The problem is I want it to run in cron&lt;BR /&gt;every 10 minutes.  Well, I did that and I kept&lt;BR /&gt;getting emails telling me the same thing.&lt;BR /&gt;&lt;BR /&gt;So I need to have an output file i.e. "sentmail" so it will not send me the same&lt;BR /&gt;email every 10 minutes.&lt;BR /&gt;&lt;BR /&gt;Here's my script, I need help creating and&lt;BR /&gt;testing the sentemail file.  I'm not sure how&lt;BR /&gt;the logic works:&lt;BR /&gt;&lt;BR /&gt;!/usr/bin/ksh&lt;BR /&gt;#                                                                             #&lt;BR /&gt;DATE=`date "+%b %d"`&lt;BR /&gt;HOST=`uname -n`&lt;BR /&gt;&lt;BR /&gt;#ADMIN_PAGER=9131234420@messaging.sprintpcs.com&lt;BR /&gt;ADMIN_EMAIL=lakrumrey@statestreetkc.com &lt;BR /&gt;&lt;BR /&gt;# Check to see if any of the servers are going down (shutdown or reboot)&lt;BR /&gt;&lt;BR /&gt;if [ `grep -i "going down" /var/adm/syslog/syslog.log | wc -l` &amp;gt; 0 ]&lt;BR /&gt;&lt;BR /&gt;then&lt;BR /&gt;grep "$DATE"  /var/adm/syslog/syslog.log | grep  "Going down" | mailx -s "Server Going Down" $ADMIN_EMAIL&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Oct 2001 15:47:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603277#M34642</guid>
      <dc:creator>Laurie A. Krumrey</dc:creator>
      <dc:date>2001-10-29T15:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603278#M34643</link>
      <description>Hi Laurie,&lt;BR /&gt;We run script every 10 minutes to check for n servers and if anyone is not reachable it sends me email.&lt;BR /&gt;Here is the loop without going through variable initilization.&lt;BR /&gt;&lt;BR /&gt;for MACHINE in $MACHINES; do&lt;BR /&gt;  RESULT=`$PING $MACHINE $BYTES $COUNT | grep "packet loss" | sed 's/%//g' | awk '&lt;BR /&gt;{print $7}'`&lt;BR /&gt;  if [ "$RESULT" = "" ]; then&lt;BR /&gt;    echo "Unexpected ping response from $MACHINE"&lt;BR /&gt;  elif [ $RESULT -ge 100 ]; then&lt;BR /&gt;    WASDOWN=`grep "^$MACHINE:" $OLDLIST | wc -l`&lt;BR /&gt;    if [ $WASDOWN -gt 0 ]; then&lt;BR /&gt;      grep "^$MACHINE:" $OLDLIST &amp;gt;&amp;gt; $NEWLIST &lt;BR /&gt;    else&lt;BR /&gt;      SENDMAIL=1&lt;BR /&gt;      echo "$MACHINE:   $DATE" &amp;gt;&amp;gt; $NEWLIST&lt;BR /&gt;      echo "$MACHINE NOT RESPONDING" &amp;gt;&amp;gt; $MAILFILE&lt;BR /&gt;    fi&lt;BR /&gt;  else&lt;BR /&gt;    WASDOWN=`grep "^$MACHINE:" $OLDLIST | wc -l`&lt;BR /&gt;    if [ $WASDOWN -gt 0 ]; then&lt;BR /&gt;      SENDMAIL=1&lt;BR /&gt;      echo "$MACHINE now responding, down from `grep \"^$MACHINE:\" $OLDLIST`" &amp;gt;&amp;gt; &lt;BR /&gt;$MAILFILE&lt;BR /&gt;      echo "`grep \"^$MACHINE:\" $OLDLIST` ---&amp;gt; $DATE" &amp;gt;&amp;gt; $LOGFILE&lt;BR /&gt;    fi&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Sachin</description>
      <pubDate>Mon, 29 Oct 2001 15:59:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603278#M34643</guid>
      <dc:creator>Sachin Patel</dc:creator>
      <dc:date>2001-10-29T15:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603279#M34644</link>
      <description>This might be a bit overkill, but Big Brother does everything that you've asked and much more.  You can get Big Brother from:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://bb4.com" target="_blank"&gt;http://bb4.com&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Also, since most of BB is shell scripts, its very platform independant.  Hope this helps.&lt;BR /&gt;&lt;BR /&gt;-Santosh</description>
      <pubDate>Mon, 29 Oct 2001 16:06:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603279#M34644</guid>
      <dc:creator>Santosh Nair_1</dc:creator>
      <dc:date>2001-10-29T16:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603280#M34645</link>
      <description>Laurie,&lt;BR /&gt;&lt;BR /&gt;You can follow this logic .&lt;BR /&gt;&lt;BR /&gt;1. Your script is valid for the first time. But what you need to do is to take the last line of the output and put the time stamp with the server name in a history file. tail -1 does the trick here.&lt;BR /&gt;&lt;BR /&gt;2. Again, run your script. Now you verify this last line with that is already there in the history file. If they match, then don't send page. Else send page, and keep the new entry in the history file. You can use this history file later to calculate the downtimes. Or you can delete the entry if you don't want.&lt;BR /&gt;&lt;BR /&gt;3. Repeat step 2 for all the entries.&lt;BR /&gt;&lt;BR /&gt;The script would be like this. You may need to modify it.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;HIST=/var/adm/history&lt;BR /&gt;DATE=`date "+%b %d"` &lt;BR /&gt;HOST=`uname -n` &lt;BR /&gt;#ADMIN_PAGER=9131234420@messaging.sprintpcs.com &lt;BR /&gt;ADMIN_EMAIL=lakrumrey@statestreetkc.com &lt;BR /&gt;&lt;BR /&gt;# Check to see if any of the servers are going down (shutdown or reboot) &lt;BR /&gt;&lt;BR /&gt;LINE=`grep -i "going down" /var/adm/syslog | tail -1`&lt;BR /&gt;MYHOST=`echo $LINE|awk '{print $4}'`&lt;BR /&gt;MYTIME=`echo $LINE|awk '{print $1$2$3}'`&lt;BR /&gt;grep $MYHOST:$MYTIME $HIST &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;if [ $? != 0 ]&lt;BR /&gt;then&lt;BR /&gt;echo "$MYHOST went down at $MYDATE" |mailx -s &lt;BR /&gt;"$MYHOST went down" $ADMIN_EMAIL&lt;BR /&gt;echo "$MYHOST:$MYTIME" &amp;gt;&amp;gt; $HIST&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Oct 2001 16:06:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603280#M34645</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-10-29T16:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603281#M34646</link>
      <description>You might also want to add a feature that will resend the page/email if you don't acknowledge it within a certain time period. That  will increase your chances of receiving a page, because we all know that pagers aren't  100% reliable.&lt;BR /&gt;&lt;BR /&gt;There is also software that will leave you a voice mail, and with some phone systems you can have it page you when you get voice mail. They usually will continue paging you until you acknowledge it.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;&lt;BR /&gt;harry</description>
      <pubDate>Mon, 29 Oct 2001 16:07:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603281#M34646</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2001-10-29T16:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603282#M34647</link>
      <description>Laurie,&lt;BR /&gt;&lt;BR /&gt;You can follow this logic .&lt;BR /&gt;&lt;BR /&gt;1. Your script is valid for the first time. But what you need to do is to take the last line of the output and put the time stamp with the server name in a history file. tail -1 does the trick here.&lt;BR /&gt;&lt;BR /&gt;2. Again, run your script. Now you verify this last line with that is already there in the history file. If they match, then don't send page. Else send page, and keep the new entry in the history file. You can use this history file later to calculate the downtimes. Or you can delete the entry if you don't want.&lt;BR /&gt;&lt;BR /&gt;3. Repeat step 2 for all the entries.&lt;BR /&gt;&lt;BR /&gt;The script would be like this. You may need to modify it.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;HIST=/var/adm/history&lt;BR /&gt;DATE=`date "+%b %d"` &lt;BR /&gt;HOST=`uname -n` &lt;BR /&gt;#ADMIN_PAGER=9131234420@messaging.sprintpcs.com &lt;BR /&gt;ADMIN_EMAIL=lakrumrey@statestreetkc.com &lt;BR /&gt;&lt;BR /&gt;# Check to see if any of the servers are going down (shutdown or reboot) &lt;BR /&gt;&lt;BR /&gt;LINE=`grep -i "going down" /var/adm/syslog | tail -1`&lt;BR /&gt;&lt;BR /&gt;if [ $LINE ]&lt;BR /&gt;then&lt;BR /&gt;MYHOST=`echo $LINE|awk '{print $4}'`&lt;BR /&gt;MYTIME=`echo $LINE|awk '{print $1$2$3}'`&lt;BR /&gt;grep $MYHOST:$MYTIME $HIST &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;if [ $? != 0 ]&lt;BR /&gt;then&lt;BR /&gt;echo "$MYHOST went down at $MYDATE" |mailx -s &lt;BR /&gt;"$MYHOST went down" $ADMIN_EMAIL&lt;BR /&gt;echo "$MYHOST:$MYTIME" &amp;gt;&amp;gt; $HIST&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Oct 2001 16:07:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603282#M34647</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-10-29T16:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603283#M34648</link>
      <description>Laurie,&lt;BR /&gt;&lt;BR /&gt;Try this page, you will be able to customize this software and it will provide you with alot of future functionality.&lt;BR /&gt;&lt;BR /&gt;Enjoy,&lt;BR /&gt;Craig&lt;BR /&gt;&lt;A href="http://www.cert.dfn.de/eng/logsurf/" target="_blank"&gt;http://www.cert.dfn.de/eng/logsurf/&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Oct 2001 16:10:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603283#M34648</guid>
      <dc:creator>Craig Rants</dc:creator>
      <dc:date>2001-10-29T16:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603284#M34649</link>
      <description>If ytou get tired of your scripting, you might also try looking at netsaint.  It does more than just a ping sweep.  You can get all kinds of info out of the system agents.  Runs best on linux, though...</description>
      <pubDate>Mon, 29 Oct 2001 16:29:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603284#M34649</guid>
      <dc:creator>John Payne_2</dc:creator>
      <dc:date>2001-10-29T16:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603285#M34650</link>
      <description>Hi Sachin,&lt;BR /&gt;&lt;BR /&gt;I am also using your ping script.  Everything works when my server is down. How do I get it&lt;BR /&gt;to just send me one email and not keep repeating itself?&lt;BR /&gt;&lt;BR /&gt;What did I miss?&lt;BR /&gt;&lt;BR /&gt;for MACHINE in $MACHINE; &lt;BR /&gt; do &lt;BR /&gt;&lt;BR /&gt;RESULT=`$PING $MACHINE $BYTES $COUNT | grep "packet loss" | sed 's/%//g' | awk '&lt;BR /&gt;{print $7}'` &lt;BR /&gt;&lt;BR /&gt;if [ "$RESULT" = "" ]; then &lt;BR /&gt;echo "Unexpected ping response from $MACHINE" &lt;BR /&gt;&lt;BR /&gt;elif [ $RESULT -ge 100 ]; then &lt;BR /&gt;WASDOWN=`grep "^$MACHINE:" $OLDLIST | wc -l` &lt;BR /&gt;&lt;BR /&gt;if [ $WASDOWN -gt 0 ]; then &lt;BR /&gt;grep "^$MACHINE:" $OLDLIST &amp;gt;&amp;gt; $NEWLIST &lt;BR /&gt;&lt;BR /&gt;echo "Cannot ping $MACHINE" | mailx -s "$MACHINE NOT RESPONDING" $ADMIN_EMAIL&lt;BR /&gt;fi&lt;BR /&gt;else&lt;BR /&gt;&lt;BR /&gt;WASDOWN=`grep "^$MACHINE:" $OLDLIST | wc -l`&lt;BR /&gt;&lt;BR /&gt;if [ $WASDOWN -gt 0 ]; then&lt;BR /&gt;SENDMAIL=1&lt;BR /&gt;&lt;BR /&gt;echo "$MACHINE now responding, down from `grep \"^$MACHINE:\" $OLDLIST`" |mailx -s "$MYHOST Down" $ADMIN_EMAIL&lt;BR /&gt;&lt;BR /&gt;echo "`grep \"^$MACHINE:\" $OLDLIST` ---&amp;gt; $DATE" &amp;gt;&amp;gt; $LOGFILE&lt;BR /&gt;fi&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Oct 2001 17:16:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603285#M34650</guid>
      <dc:creator>Laurie A. Krumrey</dc:creator>
      <dc:date>2001-10-30T17:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603286#M34651</link>
      <description>Another idea I haven't seen mentioned yet, if you just want to send out a message when a server is being rebooted/shutdown, you could simply put a script in /sbin/rc3.d/K100goingdown.  Then that script could send out your message.  This wouldn't have to be in rc3.d, it could be in rc2.d as well, just make sure it starts with a K and is listed before the network stuff is shutdown.&lt;BR /&gt;&lt;BR /&gt;One more option, if you have a central server that is consolidating syslog stuff, why not configuring syslog.conf on your server to send all its messages to that other server.  Then you can set up a script on one server to look for errors/messages from all your servers. There are several good scripts out there search through a log file and filter out what you want.&lt;BR /&gt;&lt;BR /&gt;That said, having some kind of real-time monitoring system as is mentioned above is still the best way to know when your server is down, as systems as known to crash or go down ungracefully without going through the proper shutdown sequence.</description>
      <pubDate>Tue, 30 Oct 2001 17:37:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603286#M34651</guid>
      <dc:creator>Bernie Vande Griend</dc:creator>
      <dc:date>2001-10-30T17:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Need Scripting Help - Script to send email if server goes down</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603287#M34652</link>
      <description>Hi Lauri,&lt;BR /&gt;You need simple trick. &lt;BR /&gt;&lt;BR /&gt;#folloing .new and .old file will do that trick&lt;BR /&gt;NEWLIST="/tmp/server_ping.new"&lt;BR /&gt;OLDLIST="/tmp/server_ping.old"&lt;BR /&gt;MAILFILE="/tmp/server_ping.mail"&lt;BR /&gt;MAILUSERS="sachin"&lt;BR /&gt;SENDMAIL=0&lt;BR /&gt;BYTES=64&lt;BR /&gt;COUNT=4&lt;BR /&gt;DATE=`date`&lt;BR /&gt;&lt;BR /&gt;PING=/etc/ping&lt;BR /&gt;&lt;BR /&gt;DIRNAME=`dirname $0`&lt;BR /&gt;MACHINES="server1 server2 server3...."&lt;BR /&gt;LOGFILE="$DIRNAME/uptime.log"&lt;BR /&gt;&lt;BR /&gt;# If there is no old list file create one&lt;BR /&gt;if [ ! -f $OLDLIST ]; then&lt;BR /&gt;  echo "" &amp;gt; $OLDLIST&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;echo "Current Time: $DATE" &amp;gt; $MAILFILE&lt;BR /&gt;echo "" &amp;gt;&amp;gt; $MAILFILE&lt;BR /&gt;echo "" &amp;gt; $NEWLIST&lt;BR /&gt;&lt;BR /&gt;&lt;YOUR for="" loop=""&gt;&lt;BR /&gt;&lt;BR /&gt;# Where mail is required&lt;BR /&gt;if [ $SENDMAIL -eq 1 ]; then&lt;BR /&gt;  echo "" &amp;gt;&amp;gt; $MAILFILE&lt;BR /&gt;  echo "Machines currently down:" &amp;gt;&amp;gt; $MAILFILE&lt;BR /&gt;  cat $NEWLIST &amp;gt;&amp;gt; $MAILFILE&lt;BR /&gt;  mailx -s "Server Uptime Change" $MAILUSERS &amp;lt; $MAILFILE&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;#Update old list file&lt;BR /&gt;cp $NEWLIST $OLDLIST&lt;BR /&gt;&lt;BR /&gt;Now you have $OLDLIST file and so it will not send you eamil again for that system. It will send you email when that system is up again or other system goes down.&lt;BR /&gt;&lt;BR /&gt;Sachin&lt;/YOUR&gt;</description>
      <pubDate>Tue, 30 Oct 2001 18:38:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help-script-to-send-email-if-server-goes-down/m-p/2603287#M34652</guid>
      <dc:creator>Sachin Patel</dc:creator>
      <dc:date>2001-10-30T18:38:41Z</dc:date>
    </item>
  </channel>
</rss>

