Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Output from Expect-SSH session is all jumbled

by salva (Abbot)
on May 20, 2013 at 08:10 UTC ( #1034294=note: print w/ replies, xml ) Need Help??


in reply to Output from Expect-SSH session is all jumbled

be lazy!

use Net::OpenSSH; my $hostname ='50.10.0.11'; my $username ='root'; my $password ="mypassword"; my $timeout = 15; my $mac = "00:25:B5:11:11:12"; my $ssh = Net::OpenSSH->new($hostname, timeout => $timeout, user => $username, password => $password); $ssh->error and die "unable to connect to remote host: " . $ssh->error +; my ($dhcpip) = $ssh->capture("grep -i $mac /var/log/messages | grep DH +CPACK | awk {'print \$8'} |uniq"); $ssh->error and die "remote command failed: " . $ssh->error; chomp $dhcpip; my @tr_output = $ssh->capture("traceroute $dhcpip | awk '{print \$2}'" +); $ssh->error and die "remote command failed: " . $ssh->error; print "TRACEROUTE OUTPUT = @tr_output\n"; if(grep(/$dhcpip/,@tr_output)) { print "Trace route Success.. DHCP-IP = $dhcpip\n"; } else { print "Trace route : FAIL\n"; }

update: BTW, the problem in your script is that you are using the traceroute command, which contains metacharacters (specifically, |), as a regular expression. Quote it using quotemeta or just use eq instead of a regex match operation.


Comment on Re: Output from Expect-SSH session is all jumbled
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1034294]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2015-07-31 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls