in reply to Re: Ping sweep with reporting
in thread Ping sweep with reporting

Hi StarkRavingCalm,

As Fletch says, it looks like you're simply missing the '}' where marked below:

#!/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$..$/

Replies are listed 'Best First'.
Re^3: Ping sweep with reporting
by StarkRavingCalm (Sexton) on May 17, 2007 at 14:31 UTC
    Thanks for the help. I'm very new to Perl so some of this stuff can\will allude me unfortunaltly. I did see the error but what threw me off was the curly bracket right above where it said it was needed. And I'll pay more attention to my previews ; )

    Let me try adding the bracket and I'll post my results.
    Thanks!

      Ok, here's what I have:
      #!/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?
        Great ... now you're getting somewhere!

        The next step is to debug your results.

        First of all, what happens when you do the ping by hand?  To be on the safe side, you can formulate the whole command before executing it, so you can cut-and-paste:

        my $cmd = "$ping $_ 2> /dev/null"; print "Debug: command is '$cmd'\n"; my $ping_out = `$cmd`;

        So when you run that, you should get something like:

        Debug: command is '/bin/ping myserver02 2> /dev/null'

        What happens when you run that command (/bin/ping myserver02 2> /dev/null) at a shell prompt?  Does running ping directly produce the output you expect?

        If so, then try printing the output in the program, and compare it visually:

        my $ping_out = `$cmd`; chomp ($ping_out); print "Debug: ping results => '$ping_out'\n";

        Does it print the results you expect?  (ie. the results you get doing it by hand?)

        If there's a problem, you should now, most likely, know where it is.  Perhaps the remote server is down.  Or perhaps the output from ping isn't quite in a format that you expect.

        What happens when you follow these steps?  Are you able to find the bug and fix it?


        s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      Ok, here's what I have: <code> #!/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 <code/> And here's the output: root@stewie ~# perl pingsweep_pm.pl isn't pinging Thoughts?