Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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.

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 browsing the Monastery: (9)
As of 2016-10-24 21:32 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (310 votes). Check out past polls.