perl return ips after successful ping


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl return ips after successful ping
# 1  
Old 01-22-2010
perl return ips after successful ping

Hi,

I have this script in ksh, what it does is loop every ip in the nodes_nso and produced another variable up_nodes_nso of only ip's that are up.

Code:
nodes_nso=$(cat /var/tmp/nodes.txt)

echo "ICMP Tests:"
up_nodes_nso=""
for ip in ${nodes_nso} ; do
  ping ${ip} 3 > /dev/null
  if [ "${?}" -eq "0" ]; then
    status="OK"
    up_nodes_nso="${up_nodes_nso} ${ip}"
  else
    status="DOWN"
  fi
  echo "NSO Node ${ip}: ${status}"
done

I want to convert this script to perl, is there an easy way to do this
# 2  
Old 01-22-2010
There's no magical ksh2perl conversion program or method. It'll need just plain rewriting.

Why perl, though? It's such a pig of a language for such a tiny simple task, and this'd be easy enough to convert to plain sh. (There are other potential improvements, as well.) Isn't there any shell on the system?

Also, what version of ping are you using? Mine can't take an option '3' like that.

---------- Post updated at 10:12 AM ---------- Previous update was at 10:06 AM ----------

Code:
#!/usr/bin/perl

my $ip;
my @up;

open(IN1,"</tmp/nodes.txt");

while($ip=<IN1>)
{
        chomp($ip);
        if($ip != "")
        {
                $ret=system("ping -c 3 $ip > /dev/null");
                if($ret == 0)
                {       push @up, $ip;          }
        }
}

exit 0;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to end the program with a successful return code?

i have the follow shell script that try to find any file in the specified path and upload to oracle. if no file will output in the concurrent log and the program return as error , how do i change the program so that if no file found will give out normal sucessful result. i tried change the exit... (3 Replies)
Discussion started by: feilhk
3 Replies

2. Shell Programming and Scripting

Perl : ping for multiple IPs not working

I have written perl ping program to ping list of IPs one by one and print the status.But each and every time it is showing the status as Pass for all IPs even though the IP is wrong. multipleip.pl use Net::Ping; $p = Net::Ping->new(); $ifile="inventory.txt"; ... (2 Replies)
Discussion started by: scriptscript
2 Replies

3. Shell Programming and Scripting

Ping and Perl

Hi There i have little situation that i could us some help with. We have a dhcp server, but the problem is if that a machine has been offline for a while it loose it's lease and so if you ping it you get unknown host if there a way using perl that it will continue to try and ping it, even tho... (1 Reply)
Discussion started by: ab52
1 Replies

4. Programming

Perl Ping Loop

Hi All i have an issue with ping, we are using dhcp and so if the machine has been offline and i ping it, i get " ping: unknown host <hostname> is there a way i can stick a loop somewhere so it would keep trying when it got the unknown host error and then when the machine came back online... (2 Replies)
Discussion started by: ab52
2 Replies

5. Shell Programming and Scripting

How to input the return value (1 or 0) ping cmd to a variable

Hi I would like to ask about my plan script I have this several workstation want to monitor and execute a command without logging it we use "rsh $host "<command>" i create csh script using foreach to loop my several workstation, my problem with the rsh command is if it encounter a... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. Shell Programming and Scripting

Shell script to ping a range of IPs

Hi Can someone give me a shell script that can ping a range of IPs and return IPs which are not pingable. Range for example say 192.168.0.1 to 192.168.0.50 and whichever are not pingable then return the IP. Thanks for your help (3 Replies)
Discussion started by: tannu
3 Replies

7. Shell Programming and Scripting

perl ping script

Dear All Any one able been writing any command ping in perl??basically i want to wring ping script to send 1000 packet ping then initiate "Ctrl C' terminal to ping example below:-] #!/usr/local/bin/perl $r=`/bin/ping 172.23.11.254`; Thank You ---------- Post updated at 10:27 PM ----------... (2 Replies)
Discussion started by: netxus
2 Replies

8. UNIX for Dummies Questions & Answers

Is there way to ping and return boolean answer?

Hello im using sunos and i need to somehow ping other sun in the network but geting boolean return and not the "sun is alive" response can it be done ? (11 Replies)
Discussion started by: umen
11 Replies

9. Shell Programming and Scripting

Perl Ping Determine Success or Fail

I know how to ping in Perl. That is easy. What I am wondering is if there is a way for Perl to determine whether the ping was successful or not. Or do I need to save the results out and parse the results seperately looking for the #of tries and successful revieves. Thanks. (1 Reply)
Discussion started by: gdboling
1 Replies

10. Shell Programming and Scripting

PERL: ping and e-mail

I need a script to open a text file with ip's in it, ping them, split the results into the ip and time from the results and e-mail them ? here what i've done. its porbly wrong and not workin.its for win nt4 use Net::SMTP; # get list of ip's to ping open (PINGFILE, "< c:\\Documents and... (20 Replies)
Discussion started by: perleo
20 Replies
Login or Register to Ask a Question