kodo has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl -w use strict; use Net::FTP; use Net::Ping; my $serverfile = '/home/someuser/etc/checkftp/servers'; my @serverfile = (); open(FILE, "< $serverfile") || die "Couldn't open $serverfile: $!"; @serverfile = <FILE>; close(FILE); foreach(@serverfile) { chomp; my ($type, $host, $user, $pw) = split(/:/, $_); if ($type eq "ftp") { &ftpcheck($host,$user,$pw); } elsif ($type eq "ping") { &pingcheck($host); } else { print "Unknown Check: $type\n"; } } sub ftpcheck { my $ftperror = 0; my ($host, $user, $pw) = @_; my $ftp = Net::FTP->new("$host", Timeout => 6, Debug => 0) || eval { print "FTP-CHECK:\t[$host]\t\t=>\tCouldn't connect: $!\n" +; ++$ftperror; }; return; if ($ftperror eq "0") { $ftp->login($user, $pw) || eval { print "FTP-CHECK:\t[$host]\t\t=>\tCouldn't login: $!\n +"; ++$ftperror; }; } if ($ftperror eq "0") { $ftp->quit || eval { print "FTP-CHECK:\t[$host]\t\t=>\tCouldn't quit: $!\n" +; ++$ftperror; }; } if ($ftperror eq "0") { print "FTP-CHECK:\t[$host]\t\t=>\tOK.\n"; } $ftp->quit(); } sub pingcheck { my $pingerror = 0; my $host = $_[0]; my $ping = Net::Ping->new("icmp"); $ping->ping($host) || eval { print "PING-CHECK:\t[$host]\t\t=>\tCouldn't ping: $!\n"; +++$pingerror; }; if ($pingerror eq "0") { print "PING-CHECK:\t[$host]\t\t=>\tOK.\n"; } $ping->close(); }
Edit kudra, 2002-04-24 Added a readmore tag
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SUID-Taint-Problem?!
by shotgunefx (Parson) on Apr 24, 2002 at 10:21 UTC | |
by kodo (Hermit) on Apr 24, 2002 at 16:02 UTC | |
by kodo (Hermit) on Apr 24, 2002 at 11:38 UTC | |
by shotgunefx (Parson) on Apr 24, 2002 at 12:14 UTC |