Thanks for the responses guys. Yes just adding this did the trick I can see the output appended to the bottom..

$data .= $self->cmd('some other command', undef, $output_ref);

Having one problem though. If the command is not in format 'show this' I get an error. Thought it was the pipes at first but same issue when creating an alias on the remote device to run the command for me.

Essentially the command is run, grepping string and then displays the last 3 lines of the output.

$data .= $self->cmd('command | grep string | last 3', undef, $output_r +ef);

Here it is again after setting alias name of 'runthis' against 'command | grep string | last 3' on the remote device (works ok locally)

$data .= $self->cmd('runthis', undef, $output_ref);

Error is Use of uninitialized value in concatenation (.) or string... Insecure dependency in sprintf while running with -T switch at ....

Presumably the sub(s) above this command needs amending...

sub smart_cmd { my($self,$cmd,@args) = @_; return $self->show_mem if ($cmd =~ /^\s*show mem/); return $self->show_cfg if ($cmd =~ /^\s*show (conf|run)/); return $self->show_start if ($cmd =~ /^\s*show start/); return $self->set_pass($1,$2) if ($cmd =~ /^\s*set pass\S*\s+(\S+)\s ++(\S+)/); return $self->set_enablepass($1,$2) if ($cmd =~ /^\s*set enablepass\ +S*\s+(\S+)\s+(\S+)/); my($data,$match,$remainder) = $self->cmd($cmd,@args); return (wantarray)?($data,$match,$remainder):$data; } =head2 cmd(); $data = $host->cmd($cmd); ($data,$matched_prompt) = $host->cmd($cmd,$prompt);

Thanks again :)


In reply to Re: Get outputs from 2 commands and add to var by Cisco_Dave
in thread Get outputs from 2 commands and add to var by Cisco_Dave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.