Results 1 to 3 of 3
Hello ,
I am trying to write a perl script which will give an interactive session to a user to execute command on the server.
I have written a small ...
- 02-25-2011 #1
[SOLVED] Perl and Net:SSH
Hello ,
I am trying to write a perl script which will give an interactive session to a user to execute command on the server.
I have written a small script to do this :
It works fine but the problem is there when we execute "w" or "top" command on the server. It does not displays all the field for the "top" command and for "w" I am getting the following outputCode:!/usr/bin/perl -w use strict; use Net::SSH::Perl; my $host = '192.168.1.1'; my $username = 'user'; my $login_passwd = 'test123'; my $ssh = Net::SSH::Perl->new($host, $username,trace => -1); $ssh->config->set('interactive', 1) unless defined $ssh->config->get('interactive'); my $cmd; $ssh->login($username, $login_passwd); if ($cmd) { $cmd =$_; my($out, $err, $exit) = $ssh->channel($cmd); print $out if $out; print $err if $err; } else { eval "use Term::ReadKey;"; ReadMode('raw'); eval "END { ReadMode('restore') };"; $ssh->shell; print "Connection to $host closed.\n"; }
Any idea about this.Code:[root@server ~]# w 47 column window is too narrow
Thank you
Pratap
- 02-28-2011 #2
- 04-22-2011 #3
I found the solution Here is the script which does not alter the output:
You need to install Perl Module Net::OpenSSH and IO::Pty
#!/usr/bin/perl
use strict;
use warnings;
use Net::OpenSSH;
my $host = '192.168.3.37';
my $user = 'test';
my $login_passwd = 'test123';
my $ssh = Net::OpenSSH->new($host, user => $user, password => $login_passwd);
$ssh->error and die "Unable to connect to remote host: " . $ssh->error;
$ssh->system({tty => 1});
$ssh->error and die "error: " . $ssh->error;


