Re: Ping sweep with reporting
by CountOrlok (Friar) on May 14, 2007 at 20:36 UTC
|
Take a look at Net::Ping for pinging and MIME::Lite for mailing. They'll help you accomplish all this. | [reply] |
Re: Ping sweep with reporting
by shandor (Monk) on May 14, 2007 at 21:15 UTC
|
Here's a possibility from a Solaris server. Note that by default, ping on Solaris returns "server is alive" when the server can ping. Otherwise, the ping times out after a few seconds.
#!/usr/bin/perl
use strict;
use warnings;
my $ping = "/usr/sbin/ping";
while (<DATA>){
chomp;
my $ping_out = `$ping $_ 2> /dev/null`;
chomp ($ping_out);
if ($ping_out !~ /is alive/){ print "$_ isn't pinging\n"; }
}
__DATA__
server1
server2
server3
Another possibility is to use the ping -t 1 format on a linux server. If anything shows up in $ping_out, then the server is pingable, otherwise it's not. | [reply] [d/l] |
Re: Ping sweep with reporting
by kyle (Abbot) on May 14, 2007 at 20:41 UTC
|
This sounds a lot like a job that is ordinarily performed with standard network monitoring applications (such as Nagios). Is there a reason you're rolling your own, or would an existing tool be able to solve your problem?
| [reply] |
Re: Ping sweep with reporting
by StarkRavingCalm (Sexton) on May 14, 2007 at 20:56 UTC
|
Nagios is a real bear to get going. This seems like an easy script for Perl. I am a complete beginner with Perl so I look it as a chance to learn. | [reply] |
|
| [reply] |
Re: Ping sweep with reporting
by StarkRavingCalm (Sexton) on May 15, 2007 at 15:38 UTC
|
That worked. Changing to "bytes from" and also changing to /bin/ping. I am not getting any output though. | [reply] |
|
if ($ping_out !~ /bytes from/) {
print "$_ isn't pinging\n";
}
else {
print "$_ is up\n";
}
| [reply] [d/l] |
Re: Ping sweep with reporting
by StarkRavingCalm (Sexton) on May 17, 2007 at 21:36 UTC
|
#!/usr/bin/perl
use strict;
use warnings;
my $ping = "/bin/ping";
while (<DATA>) {
chomp;
my $ping_out = `$ping $_ 2> /dev/null`;
chomp ($ping_out);
if ($ping_out !~ /bytes from/) {
print "$_ isn't pinging\n";
} else {
print "$_ is up\n";
}
}
__DATA__
myserver02
And here's the output:
root@stewie ~# perl pingsweep_pm.pl
isn't pinging
Thoughts? | [reply] [d/l] |
Re: Ping sweep with reporting
by StarkRavingCalm (Sexton) on May 16, 2007 at 23:23 UTC
|
Ok, so I have updated the script with the suggestions. I now looks like this:
#!/usr/bin/perl
use strict;
use warnings;
my $ping = "/bin/ping";
while (<DATA>){
chomp;
my $ping_out = `$ping $_ 2> /dev/null`;
chomp ($ping_out);
if ($ping_out !~ /bytes from/) {
print "$_ isn't pinging\n";
}
else {
print "$_ is up\n";
}
__DATA__
SERVER01
SERVER02
But.. I receive this when I run it:
[root@stewie ~]# perl 615424.pl
Missing right curly or square bracket at 615424.pl line 17, at end of
+line
syntax error at 615424.pl line 17, at EOF
Execution of 615424.pl aborted due to compilation errors.
Any clues??
Edit: g0n - code tags | [reply] [d/l] [select] |
|
#!/usr/bin/perl
use strict;
use warnings;
my $ping = "/bin/ping";
while (<DATA>) {
chomp;
my $ping_out = `$ping $_ 2> /dev/null`;
chomp ($ping_out);
if ($ping_out !~ /bytes from/) {
print "$_ isn't pinging\n";
} else {
print "$_ is up\n";
}
# <--- You're missing a '}' right here to end the while { } loop
__DATA__
SERVER01
SERVER02
Was there some reason that "Missing right curly or square bracket" didn't lead you to that conclusion?
And do you understand how to put <code> and </code> tags around your post so that it's readable? If not, pay close attention when you hit "preview". If it doesn't look right, don't click the "create" button until it does! (You can continue clicking on "preview" until the post displays correctly).
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
| [reply] [d/l] |
|
| [reply] |
|
|
|
|
Hard to tell since you didn't use <code></code> tags around it, but you're missing the } to close the while loop on or around line 17 of your source (before the DATA marker). Just like the error message says.
Seems to be a lot of that going around today. Did someone declare today "'Ignore the simple error message which explicitly states what's wrong' Day" and I just didn't get the memo?
| [reply] [d/l] [select] |
A reply falls below the community's threshold of quality. You may see it by logging in. |