Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 =''; 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?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2015-11-29 21:38 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (753 votes), past polls