bellis has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
Long time viewer, first time poster. Love the work of everyone in this community.
I am attempting to SSH into a node, run and capture various different commands, then process the outputs and present to the user.
Using shell() the below script works, however I want to capture the command output so it can be process it before printing.
Is there a way to capture the output instead of printing it to the user?
#!/usr/bin/perl use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2 -> connect ($ip) or die $!; $ssh2 -> auth_password ($user,$pass); my $chan = $ssh2->channel(); $chan->shell(); print $chan "$cmd1\n"; print "$_" while <$chan>; print $chan "$cmd2\n"; print "$_" while <$chan>; print $chan "$cmd3\n"; print "$_" while <$chan>; print $chan "$cmd4\n"; print "$_" while <$chan>; $chan->close; $ssh2->disconnect;
Your assistance is greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SSH2 to capture multiple commands on remote system
by salva (Canon) on Sep 16, 2014 at 08:44 UTC | |
by bellis (Initiate) on Sep 17, 2014 at 04:47 UTC | |
by salva (Canon) on Sep 17, 2014 at 07:27 UTC | |
|
Re: Net::SSH2 to capture multiple commands on remote system
by jellisii2 (Hermit) on Sep 16, 2014 at 11:35 UTC | |
|
Re: Net::SSH2 to capture multiple commands on remote system
by thanos1983 (Parson) on Sep 16, 2014 at 11:52 UTC |