Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-02-20 21:59 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (274 votes). Check out past polls.