WaltSteadman
MIS
Greetings all,
Still in pursuit of a good login for my non interactive devices. I started reading about Net::SSH::Expect and I think my problem might be how it talks to SSH as I get output from the script, but I am not getting all of the output and I am not sure why.
this is the output I get from the code below:
[root@wally-lnx cgi-bin]# perl mytest.cgi
This is the login promt
Last login: Fri Mar 28 13:33:56 2008 from localhost.localdomain
[wally@wally-lnx ~]$
this is the ls
Test Printing
Test Print 2
[root@wally-lnx cgi-bin]#
I am not sure why I am not getting the simple ls command results back and would appreciate any assistance.
I added a few additional print lines to ensure that I am getting any output and I even added text into the line where the ls is returned and I see that also so not sure why I am not seeing the ls itself.
Code is below:
Still in pursuit of a good login for my non interactive devices. I started reading about Net::SSH::Expect and I think my problem might be how it talks to SSH as I get output from the script, but I am not getting all of the output and I am not sure why.
this is the output I get from the code below:
[root@wally-lnx cgi-bin]# perl mytest.cgi
This is the login promt
Last login: Fri Mar 28 13:33:56 2008 from localhost.localdomain
[wally@wally-lnx ~]$
this is the ls
Test Printing
Test Print 2
[root@wally-lnx cgi-bin]#
I am not sure why I am not getting the simple ls command results back and would appreciate any assistance.
I added a few additional print lines to ensure that I am getting any output and I even added text into the line where the ls is returned and I see that also so not sure why I am not seeing the ls itself.
Code is below:
Code:
#! /usr/bin/perl -w
use Net::SSH::Expect;
#
# You can do SSH authentication with user-password or without it.
#
# Making an ssh connection with user-password authentication
# 1) construct the object
my $ssh = Net::SSH::Expect->new (
host => "localhost",
password=> 'mypassword',
user => 'myusername',
raw_pty => 1,
);
# 2) logon to the SSH server using those credentials.
# test the login output to make sure we had success
my $login_output = $ssh->login();
print "This is the login promt $login_output";
print "\n";
if ($login_output !~ /login/) {
die "Login has failed. Login output was $login_output";
}
# 2) now start the ssh process
$ssh->run_ssh() or die "SSH process couldn't start: $!";
# 3) you should be logged on now. Test if you received the remote prompt:
($ssh->read_all(2) =~ /wally/) or die "where's the remote prompt?";
# - now you know you're logged in - #
# disable terminal translations and echo on the SSH server
# executing on the server the stty command:
$ssh->exec("stty raw -echo");
# runs arbitrary commands and print their outputs
# (including the remote prompt comming at the end)
my $ls = $ssh->exec("ls /home/wally");
print ("this is the ls $ls\n");
print ("Test Printing\n");
print "Test Print 2\n";
$ssh->close();