home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 January, February, March & April
/
Chip-Cover-CD-2007-02.iso
/
boot
/
i386
/
root
/
usr
/
lib
/
YaST2
/
servers_non_y2
/
ag_ping
< prev
next >
Wrap
Text File
|
2006-11-29
|
2KB
|
74 lines
#!/usr/bin/perl
use lib "/usr/lib/YaST2/agents_non_y2";
use ycp;
use Net::Ping;
use diagnostics;
use strict;
my $result;
while ( <STDIN> )
{
# ycpDoVerboseLog();
ycpInit( $_ );
#----------------------------------------------------------
# Check the Command
# We expect a `Execute( .ping, [ <host1>,<host2> ...]);
#----------------------------------------------------------
if ( ycpCommandIsExecute && ycpArgIsList )
{
y2debug( "Now we check with ping the hosts:", ycpGetArgList );
##########################################
# OUR PERL MAIN
##########################################
# get the list of hosts
my @host_array = ycpGetArgList;
my %result;
my $host;
# send a ping to all hosts
my $p = Net::Ping->new("icmp");
foreach $host (@host_array)
{
if ( $p->ping($host, 1) )
{
$result{$host} = " alive";
}
else
{
$result{$host} = "NOT alive";
}
}
$p->close();
# for debug purpose: print a result list to /var/log/YaST2/y2log
while (( $host, my $alive) = each(%result))
{
y2debug( $alive, ": Host", $host);
}
##########################################
# END of PERL MAIN
##########################################
ycpReturnHashAsMap( %result );
}
else
{
my $return_value = sprintf( "Unknown instruction %s or argument: %s", ycpGetCommand, ycpGetArgType);
ycpReturnSkalarAsString( $return_value );
}
}
# end