Operating System - HP-UX
1757084 Members
2614 Online
108858 Solutions
New Discussion юеВ

Shell Script for grep one IP from one server and ping to another

 
Sac77
Advisor

Shell Script for grep one IP from one server and ping to another

Hi Guys,

My enviorment got two node cluster and on primary node i've configration file which consist the IP address and i want to grep this Ip and ping this IP address from secondry node. please help. thanks
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: Shell Script for grep one IP from one server and ping to another

>I've configuration file which consist the IP address

If it just contains IP addresses you can do:
for m in $(< file); do
ping $m -n 2
done
Sac77
Advisor

Re: Shell Script for grep one IP from one server and ping to another

But I want to ping to different server not on the same.
Sac77
Advisor

Re: Shell Script for grep one IP from one server and ping to another

Denis,

the below script what i've written, but my problem is how should i break my inner loop to restart the script again...

#!/bin/sh

for i in `cat /var/adm/crash/list`
do
remsh $i grep xx /etc/hosts > sss
OUT=$(awk '{print $2}' sss)
for l in `cat list2`
do
echo "#############"
echo $l
echo "#############"
remsh $l /etc/ping $OUT -n 4
echo
echo
done
\rm sss
done
Suraj K Sankari
Honored Contributor

Re: Shell Script for grep one IP from one server and ping to another

Hi,
If your script is running fine then use while loop it will run till you break the loop with CTRL+C

while true
do
for i in `cat /var/adm/crash/list`
do
remsh $i grep xx /etc/hosts > sss
OUT=$(awk '{print $2}' sss)
for l in `cat list2`
do
echo "#############"
echo $l
echo "#############"
remsh $l /etc/ping $OUT -n 4
echo
echo
done
\rm sss
done
done

Suraj
Wim Rombauts
Honored Contributor

Re: Shell Script for grep one IP from one server and ping to another

Well, you hav a two-node cluster and since you log it on the HP-UX forum, I presume you are running ServiceGuard, right ?

Then why won't you let ServiceGuard handle this ? It has built-in functionality to monitor IP-traffic to a card and restart/switch software when communication dies.
Dennis Handly
Acclaimed Contributor

Re: Shell Script for grep one IP from one server and ping to another

>but my problem is how should i break my inner loop to restart the script again

You can add "-m timeout" so ping times out.