Monks,
I have this simple piece of code using Net::SSH::Perl to login to a remote host using ssh and return the output of a df -k. This works just fine.
#!/usr/bin/perl
use Net::SSH::Perl;
use strict;
my ($auto_serv, $search_string, $insert_cmd ) = @_;
my $cibs_host="www.myhost.com";
my $user = "userid";
my $cnt = 1;
my $line;
my $ssh = Net::SSH::Perl->new($cibs_host, options => [
"Protocol 2,1",
"Debug 2",
"identity_files id_dsa"]);
$ssh->login($user);
my (@out1, $err1, $exit2) = $ssh->cmd("df -k");
foreach $line(@out1) {
print "$cnt: $line\n";
$cnt++;
}
The problem is the output returned from @out1. Each line of the df -k is not retrieved as a line with a ("\n"). Instead the entire contents of a df -k are contained in one line. I need to be able to parse this output line-for-line. Would anyone know how I can do this? Or rather, what am I doing wrong?
I added the $cnt so I could determine what is being outputed. The entire contents of the df -k end up on 1: or line 1.
Thanks,
Louis
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.