Loading ...
Sorry, an error occurred while loading the content.

How to open a remote shell using perl

Expand Messages
  • off_gl@yahoo.com
    Hello I want to open a remote ssh session using the perl script , I am able to login to the server using the simple script and i am also able to execute few
    Message 1 of 1 , Aug 25, 2010
    • 0 Attachment
      Hello

      I want to open a remote ssh session using the perl script , I am able to login
      to the server using the simple script and i am also able to execute few
      commands on the server.


      I am writing a script which takes the user name , password and hostname from the
      database and login to the server .

      I need to run command once I have logged in using my script and I want to track
      down all the commands being executed in a particular session.

      I know how to run command on remote shell using script , but I want to open
      remote shell using perl and want to run the command manually and terminate the
      session when I am done as we normally do with bash shell .


      Here is my code which logs in and performs some task but it does not show the
      output of top and pstree command what would i do to get the output of these
      commands along with "vmstat 1 10" and "iostat 1" , "top -cd2" etc..



      #!/usr/bin/perl -w
      use Net::SSH::Perl

      $host = '192.168.3.36';
      $username = 'root';
      $login_passwd = 'password';

      my $ssh = Net::SSH::Perl->new($host);


      $ssh->login($username, $login_passwd);

      while(<>) {
      $cmd = $_;
      my($stdout,$sterr, $stderr) = $ssh->cmd("$cmd");
      print "\n$stdout\n$stderr ";
      print "logging out from the server " if eof;
      }

      Thanks
      Pratap




      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.