1753797 Members
7895 Online
108805 Solutions
New Discussion юеВ

Re: ping-t script

 
mo jaber
Occasional Contributor

ping-t script

I need a script that recievs an IP adress and a number of seconds (X secodns). and every X seconds reports if the IP replies.
4 REPLIES 4
Fred Ruffet
Honored Contributor

Re: ping-t script

#!/bin/sh

IP=$1
SECS=$2
while true
do
ping -c 1 $IP
sleep $SECS
done

---

You can add controls, but it might work...
--

"Reality is just a point of view." (P. K. D.)
mo jaber
Occasional Contributor

Re: ping-t script

thanks for this answer.
but can you write it without using "do" or "while".
Fred Ruffet
Honored Contributor

Re: ping-t script

I made a mistake :
it is ping $IP -n 1 (-c 1 must be on other system)

If you want it without while and do, just do :
alias bloup=while
aliad foo=do
bloup true
foo
ping $IP -n 1
sleep $SECS
done

here it is :)
--

"Reality is just a point of view." (P. K. D.)
Dave La Mar
Honored Contributor

Re: ping-t script

Mo -
As Fred suggests, you will wnat this to run in some window of time and most likely not into infinity.
Thus you will want a conditional statement of some sort to limit this window.
i.e.
limit=`date +%H`
while [ $limit -lt 17 ]
do
ping 10.0.0.45 -n 5 > /tmp/ping_file
limit=`date +%H`
done

Best regards,
fl
"I'm not dumb. I just have a command of thoroughly useless information."