- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script using PING command
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
10-28-2002 12:20 PM
10-28-2002 12:20 PM
which will read the file(contains IP address only)
and check the each IPaddress responce from the PING command,
and generates/append the file output for each IP address log file
(MONTH_IPADDRESS.XLS).
(MMDDHHMI - means MONTH date hours minutes - )
MONTH_IPADDRESS.XLS
if the PING is successful(0% pocket loss),
then append the follwing data
--------------------
MMDDHHMI 100
---------------------
if the PING is not successful(100% pocket loss),
then append the follwing data
--------------------
MMDDHHMI 0
---------------------
if the date is 1st of the month
the file (MONTH_IPADDRESS.XLS)
should be created , otherwise appended.
$cat ipfile
IPADDRESS1
IPADDRESS2
IPADDRESS3
$cat MM_IPADDRESS1.xls
10281010 100
10281020 100
10281030 100 - 100 is uptime.
10281040 0 - 0 is downtime.
10281050 0
10281100 100
10281110 100
10281115 100
MMDDHHMI 100
(basically I am trying to generate excel file
to show the graph of UPTIME of all the servers)
Thnx in Advance .
VB
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2002 12:36 PM
10-28-2002 12:36 PM
Re: shell script using PING command
#! /bin/sh
host=`cat ipfile`
for item in $host
do
echo "Checking $host..."
ping_status=`ping $host 10|grep 'no answer'`
if [ "ping_status" ]; then
echo "$host NOT RESPONDING"
echo " "
continue
fi
echo "$host UP"
Ofcourse this is going to generate a TEXT file which you can import to Excel. You could also modify the echo commands to suit ur needs.
Cheers
Govind
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2002 12:59 PM
10-28-2002 12:59 PM
Re: shell script using PING command
ping.pl -t 10 remote_host
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Host ok"
else
echo "Host Bad"
fi
and a timeout of 10 seconds is set.
Invoke it as ping.pl -u for full usage.
The idea is to call the perl script for each host and simply look at the return status - 0 means good. That's much easier than parsing for packet loss and it includes an adjustable timeout.
The rest of the script should be very easy but is left as an exercise for the reader.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2002 01:13 PM
10-28-2002 01:13 PM
SolutionNormally I don't reply with an entire script but here's one for you.
#!/usr/bin/sh
hostsfile=/tmp/hosts_to_ping
DAY=`date +%d`
cat $hostsfile | while read addr
do
OUTFILE=`date +%b`_$addr.XLS
if [ $DAY = 1 ]
then
>$OUTFILE
fi
/usr/sbin/ping $addr -n 3 | grep -q "100% packet loss"
if [ $? != 0 ]
then
# location is up
PCT=100
else
# location is down
PCT=0
fi
echo `date +%m%d%H%M` $PCT >>$OUTFILE
done
I wouldn't trust the results of 1 single ping (hence -n 3).
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2002 07:44 PM
10-28-2002 07:44 PM
Re: shell script using PING command
What makes more sense is to use ping as a front end, then remsh (remote shell) or ssh to query the server for it's current uptime.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2002 06:35 AM
10-30-2002 06:35 AM