1748279 Members
4245 Online
108761 Solutions
New Discussion юеВ

Re: "for" instructions

 
SOLVED
Go to solution
Alpha977
Valued Contributor

"for" instructions

Hello to all!

i need to "ping" some nodes in my network.
Ping from 192.168.0.1 to 192.168.0.255.

I'm think to do a "for" action like this pseduo-code:

for ( i = 1; i< 255; i++)
{
ping 192.168.0. + "i"
}

but i don't know how to put this into my Hp-UX (PA-RISC) shell.

How i can do?

Thanks to all!

Points for all reply
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: "for" instructions


#!/usr/bin/sh

typeset -i i=1
typeset PREFIX="192.168.0."
typeset IP=""
while [[ ${i} -lt 255 ]]
do
IP="${PREFIX}${i}"
ping ${IP}
((i += 1))
done
If it ain't broke, I can fix that.
Peter Nikitka
Honored Contributor

Re: "for" instructions

Hi,
the semantic depends on your shell.
Posix (ksh):
typeset -i i=0
while [ i+=1 -lt 255 ]
do ping 192.168.0.$i
done

(T)csh:
set i=1
while ($i < 255)
ping 192.168.0.$i
@ i++
end


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Alpha977
Valued Contributor

Re: "for" instructions

I need this!

Thanks to all!