Guest User

Untitled

a guest
Jul 11th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3.  
  4. use warnings;
  5.  
  6. $| = 1;
  7.  
  8. $pid = open (SSH,"| ssh user@host");
  9.  
  10. if(defined($pid)){
  11. if(!$pid){
  12. #child
  13. while(<>){
  14. print;
  15. }
  16. }else{
  17. select SSH;
  18. $| = 1;
  19.  
  20. select STDIN;
  21.  
  22. #parent
  23. while(<>){
  24. print SSH $_;
  25. while(<SSH>){
  26. print;
  27. }
  28. }
  29. close(SSH);
  30. }
  31. }
  32.  
  33. use strict; use warnings;
  34.  
  35. my $pid = open my $SSH, '-|', 'ssh user@example.com' // die $!;
  36.  
  37. if ($pid) {
  38. while( <$SSH> ) {
  39. print $_;
  40. }
  41. }
  42. else {
  43. while( <> ) {
  44. print $SSH $_;
  45. }
  46. }
  47.  
  48. close $SSH or die $!;
  49.  
  50. use Net::OpenSSH;
  51. my $ssh = Net::OpenSSH->new($host, user => $user, password => $password);
  52. my ($in, $out, $pid) = $ssh->open2($remote_cmd);
  53.  
  54. use IPC::Open2 qw(open2);
  55. my $pid = open2(my $in, my $out, $ssh_cmd);
Add Comment
Please, Sign In to add comment