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.
In reply to Net::SSH2 to capture multiple commands on remote system by bellis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |