Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Handling output from nslookup and ping

by Anonymous Monk
on May 04, 2004 at 22:01 UTC ( [id://350598]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This is what I am trying to do with Perl - my code is down below these instructions - the commented parts are the ones I can't figure out....

nslookup hostname- if it comes with xx.xxx.xxx.110 do nothing. If it comes back with xx.xxx.xxx.110 then; Send mail here...

ping hostname.domain.com - if no reply do nothing. If alive then;
ssh root@xx.xxx.xxx.xxx 3dpipe wideip hostname pool pool_sde_primary virtual show all - look for enabled. If not found then;

ssh root@xx.xxx.xxx.xxx 3dpipe virtual xx.xxx.xxx.110:443 disabled
ssh root@xx.xxx.xxx.xxx 3dpipe virtual xx.xxx.xxx.110:443 disabled
ssh root@xx.xxx.xxx.xxx 3dpipe virtual xx.xxx.xxx.110:443 enable
ssh root@xx.xxx.xxx.xxx 3dpipe virtual xx.xxx.xxx.110:443 enable
3dpipe wideip hostname pool pool_sde_primary virtual show all
ssh root@xx.xxx.xxx.xxx 3dpipe wideip hostname pool pool_sde_primary virtual show all
send mail blah blah Here is what I have so far....
#!/usr/bin/perl -w system("nslookup domain domain"); #if returns on 5th line "Address: xxx.xxx.xxx.110" do nothing - if no +t send mail system("ping hostname"); # if this returns "alive" then do: my $ssh = Net::SSH::Perl->new("hostname"); $ssh->cmd("3dpipe virtual xx.xxx.xxx.110:443 disabled"); $ssh->cmd("3dpipe virtual xx.xxx.xxx.110:443 disabled"); $ssh->cmd("3dpipe virtual xx.xxx.xxx.110:443 enable"); $ssh->cmd("3dpipe virtual xx.xxx.xxx.110:443 enable"); $ssh->cmd("3dpipe wideip hostname pool pool_sde_primary virtual show a +ll"); $ssh->cmd("3dpipe wideip hostname pool pool_sde_primary virtual show a +ll");

Edit by BazB: obsure IP address missed by OP, retitle from "Net::SSH schtuff...."

Replies are listed 'Best First'.
Re: Handling output from nslookup and ping.
by zakzebrowski (Curate) on May 04, 2004 at 22:11 UTC

        If all he needs is to resolve "hostname", gethostbyname() should work, comes with Perl, and may be faster.

Re: Handling output from nslookup and ping.
by eXile (Priest) on May 04, 2004 at 23:46 UTC
    Hi, In your code you still got an IP-address that is not anonymized. I'd suggest you take it out. Although Perlmonks are a friendly crowd in general, evil people might be lurking.

    8)

    update: since you posted anonymously (the irony), I guess you can't remove the IP-address yourself. I've tried to attract the attention of people who can (be gentle if I did this the wrong way).
Re: Handling output from nslookup and ping
by jbaribeault (Novice) on May 06, 2004 at 14:41 UTC
    Just a word of warning when groking output from commandline ping...it's output is SUPER buffered, which means you won't necessarily catch anything until you flush the output. I had to use an expect script to unbuffer ping's output <before> catching it.
    #!/usr/bin/expect -- # Description: unbuffer stdout of a program # Author: Don Libes, NIST eval spawn -noecho $argv set timeout -1 expect
    Call the above using unbuffer <command> Hope this keeps you out of the trap I fell into!
Re: Handling output from nslookup and ping
by bluto (Curate) on May 06, 2004 at 16:27 UTC
    Parsing ping output is not usually a good idea since it varies by machine type. If you are looking for a quick and dirty solution, you may be able to use this...
    # send 1 ping... system("ping -c 1 $host >/dev/null 2>&1"); if ($?) { # dead perhaps, or just plain slow } else { # alive }
    I'm not claiming this is good code, just easy to write, so if you need accuracy especially when a machine is slow to reply, don't use it. Also, you'll want to test this on your system's command line to make sure it returns sane exit codes -- all ping binaries are not created equal...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://350598]
Front-paged by JSchmitz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found