- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 07:17 AM
04-22-2002 07:17 AM
I have a ping script that I want to build in a condition that it emails me if during the ping routine there are any packet losses.
Here is my script that pipes the output to a log file.
In the log file, I am not sure how to grep for anything other than 0% in the packet loss.
Thank you in advance,
!/usr/bin/ksh
#
LOG_DIR=`date +"/tmp/%d"`;export LOG_DIR
mkdir -p $LOG_DIR >/dev/null 2>&1
RETVAL=0
PATH=$PATH:/usr/sam/lbin:/usr/sam/bin:/usr/bin:/usr/sbin:/sbin;export PATH
#
echo "Subject: ping sapdev Report for "`date` >>$LOG_DIR/pingsap.$$
date >> $LOG_DIR/pingsap
ping 10.10.12.52 -n 20 >>$LOG_DIR/pingsap
#
# mail out results
#
#sendmail nickd < /tmp/pingsap.$$
rm $LOG_DIR/pingsap.$$
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 07:24 AM
04-22-2002 07:24 AM
Re: script help
Here is the script that I use. But I dont look for packet loss. This catches connection loss. You can modify it to email you if a host is down or fails. iphosts is a file with all the hostnames of ip addresses that you want to check in one collum. Like so:
servera
serverb
serverc
#!/bin/sh
LANG=C
HOSTNAME_FILE=iphosts
for host in $(cat $HOSTNAME_FILE)
do
ping $host -n 1 | grep -q '1 packets received'
if [ $? = 0 ]
then
echo "$host: OK"
else
echo "$host: FAIL"
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 07:26 AM
04-22-2002 07:26 AM
Re: script help
try with
grep 'loss'
HTH
RGDS, Holger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 07:37 AM
04-22-2002 07:37 AM
Re: script help
l1:/u/usr/merijn 102 > for 10 12 100 13.8 0 9 0.0 120
foreach? echo "--- $i%"
foreach? echo "$i% packet loss" | perl -ne 'm/([\d.]+)\s*%/&&$1>0&&print'
foreach? end
--- 10%
10% packet loss
--- 12%
12% packet loss
--- 100%
100% packet loss
--- 13.8%
13.8% packet loss
--- 0%
--- 9%
9% packet loss
--- 0.0%
--- 120%
120% packet loss
l1:/u/usr/merijn 103 >
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 07:41 AM
04-22-2002 07:41 AM
Re: script help
#
# mail out results
#
PCT=`grep \^20 $LOG_DIR/pingsap | awk -F", " '{print $3}' | awk -F"%" '{print $1}'`
if [ $PCT = 0 ]
then
:
else
sendmail nickd < /tmp/pingsap
fi
done
rm $LOG_DIR/pingsap
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 07:44 AM
04-22-2002 07:44 AM
Re: script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 08:13 AM
04-22-2002 08:13 AM
SolutionHere is what I uses
#!/bin/csh
set PING = "/etc/ping"
set COUNT = 3
set RESULT = `$PING $PLOT_SERVER -n $COUNT |grep "packet loss" | awk '{print $7}
' | sed 's/%//'`
if ($RESULT >= 100) then
echo "$PLOT_SERVER is down"
/usr/bin/mailx -s "$PLOT_SERVER is down `date`" sachin
exit
endif
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 09:15 AM
04-22-2002 09:15 AM
Re: script help
Your script sample almost works, however, I only want to grep for % >0 on each ping which is setup to run through cron.
Your script is mailing out the top of the log file on all instances and should only be sending mail on % > 0.
Nickd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 09:23 AM
04-22-2002 09:23 AM
Re: script help
Thanks for your script, but it give me an error, Unmatched `.
??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 10:13 AM
04-22-2002 10:13 AM
Re: script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 10:14 AM
04-22-2002 10:14 AM
Re: script help
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 10:27 AM
04-22-2002 10:27 AM
Re: script help
Try this ..
#
# mail out results
#
PCT=`grep \^20 $LOG_DIR/pingsap | awk -F", " '{print $3}' | awk -F"%" '{print $1}'`
if (($PCT > 0))
then
sendmail nickd < /tmp/pingsap
else
:
fi
rm $LOG_DIR/pingsap
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 06:44 PM
04-22-2002 06:44 PM
Re: script help
Here is another snippet of using 'ping' that may be useful..
cheers
Chris
ping ${SG_SERVICE_NAME} -n 3 | grep 100% >/dev/null
if [ "$?" = 0 ]; then
echo "Unable to ping${SG_SERVICE_NAME}"
echo "SG package probably down "
exit 1
else
echo "Ping of SG successful"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2002 11:00 PM
04-22-2002 11:00 PM
Re: script help
LOSS=`tail -5
if [ "$LOSS" -gt 0 ]
then
# your email
fi
Ruediger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2002 01:53 AM
04-23-2002 01:53 AM
Re: script help
CONN=`ping XX.XX.XX.XX -n 20 |grep "packet loss" | cut -d"," -f3 | cut -d"%" -f1`
if [ $CONN != 0 ]
then
mailx ...... Connection problem
else
Succesful connection
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2002 03:15 AM
04-25-2002 03:15 AM
Re: script help
Your script is almost perfect for me.
I just wanted to include the last three lines of my ping for example:
--spock PING Statistics----
20 packets transmitted, 8 packets received, 60% packet loss
round-trip (ms) min/avg/max = 20/20/21
Thu Apr 25 06:57:46 EDT 2002
To the email so that these Microsoft Network "experts" NOT ;-)have the necessary information.
Thanks.