- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- shell scriptf for ping
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
Discussions
Discussions
Forums
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
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
тАО09-26-2005 05:56 PM
тАО09-26-2005 05:56 PM
I need to know shell script which performs ping to couple of servers every 15 minutes and records the output in a file.
Thanks,
Shiv
Solved! Go to Solution.
- Tags:
- ping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2005 06:00 PM
тАО09-26-2005 06:00 PM
Re: shell scriptf for ping
#!/sbin/sh
i=1
while [ $i -eq 1 ]
do
for str in $hosts
do
echo "" >>output_file
ping $str >>output_file 2>&1
if [ $? -ne 0 ]
then
echo "There is problem while nslookup $str" >>output_file 2>&1
i=0
fi
done
sleep 900
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2005 06:00 PM
тАО09-26-2005 06:00 PM
Re: shell scriptf for ping
Sorry. Ignore my previous reply.
#!/sbin/sh
hosts="abc.xx.com xyz.ab.com"
i=1
while [ $i -eq 1 ]
do
for str in $hosts
do
echo "" >>output_file
ping $str >>output_file 2>&1
if [ $? -ne 0 ]
then
echo "There is problem while nslookup $str" >>output_file 2>&1
i=0
fi
done
sleep 900
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2005 06:01 PM
тАО09-26-2005 06:01 PM
Solution# Input
server1=
server2=
stime=900
while [ 1 ]
do
date >> /tmp/ping_$server1.log
ping $server1 -n 1 >>/tmp/ping_$server1.log
[[ $? -eq 0 ]] && echo "Ping success " || echo "Ping failure" >>/tmp/ping_$server1.log
date >> /tmp/ping_$server2.log
ping $server2 -n 1 >>/tmp/ping_$server2.log
[[ $? -eq 0 ]] && echo "Ping success" || echo "Ping failure" >>/tmp/ping_$server2.log
sleep 900
done
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2005 06:01 PM
тАО09-26-2005 06:01 PM
Re: shell scriptf for ping
You try of,
ping $str >>output_file 2>&1
will not end ;). Use count with ping.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2005 06:03 PM
тАО09-26-2005 06:03 PM
Re: shell scriptf for ping
If you are going to setup these scripts in productive environment plz use cron + scripting as,
#!/bin/ksh
# Input - Must
server1=
server2=
stime=900
date >> /tmp/ping_$server1.log
ping $server1 -n 1 >>/tmp/ping_$server1.log
[[ $? -eq 0 ]] && echo "Ping success " || echo "Ping failure" >>/tmp/ping_$server1.log 2>&1
date >> /tmp/ping_$server2.log
ping $server2 -n 1 >>/tmp/ping_$server2.log
[[ $? -eq 0 ]] && echo "Ping success" || echo "Ping failure" >>/tmp/ping_$server2.log 2>&1
# end
exit 0
# Cron Tab Setting
0,15,30,45 * * * * /tmp/ping.ksh 1>/dev/null 2>&1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2005 06:04 PM
тАО09-26-2005 06:04 PM
Re: shell scriptf for ping
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2005 06:05 PM
тАО09-26-2005 06:05 PM
Re: shell scriptf for ping
Sorry. Thought of solaris platform.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 12:49 AM
тАО09-27-2005 12:49 AM
Re: shell scriptf for ping
If you can't afford it, have a look at Big Brother:
http://www.bb4.org/
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 01:23 AM
тАО09-27-2005 01:23 AM
Re: shell scriptf for ping
This is my script use for one project.
#!/usr/bin/ksh
> /home/rajeshsb/sysstat.log
> /home/rajeshsb/downlist
for sys in `cat /home/rajeshsb/sys.list`
do
/etc/ping $sys -n 2 |grep ms >> /home/rajeshsb/sysstat.log
if [ $? -ne 0 ]
then
echo "$sys is down" >> /home/rajeshsb/downlist;
else
echo "$sys is up" > /dev/null;
fi
done
if [ -s /home/rajeshsb/downlist ]
then
cat /home/rajeshsb/downlist| mailx -s "Warning! Down System details" rajeshsb@india.hp.com
mailx -s "Warning! Down System details" rajeshsb@india.hp.com < /home/rajeshsb/downlist
fi
Usage:
The script "sysstat.sh" reads the list of systems from file "/home/rajeshsb/sys.list"
It logs as well sends the email to me
Keep on add the systems into sys.list.
Just schedule the scritp in cron.
Regards,
Rajesh