SSH and run an interactive program on another machine

J

John Call

I am trying to run a program on machine B from machine A. I need to
SSH from A to B, run the program which will ask for a password
interactively, give it the password and then disconnect.

I came across Except but cannot see how to ssh and then inside the ssh
I initiate run the program.

I have written some code with Net::SSH::perl that connects and runs
the program but it asks for the password at my command line and won't
accept it from the program.

Code:
-----------------------------
use Net::SSH::perl;

require '/storage/mu/etc_defaults.pl';

$cmd = $radius_restart_cmd;

my %params = (
protocol => 2,
);

my $ssh = Net::SSH::perl->new($radius_host, %params);
$ssh->login('root', $radius_su);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
my($stdout, $stderr, $exit) = $ssh->cmd('admin');
$ssh->debug($msg);

print "\n\n'$stdout' '$stderr' '$exit'\n\n";

-------------------

Thanks ahead of time for any ideas.

I know I should pass the password as plain text but this is just a
test and I'll clean that up later.

John Call
 
K

ko

John said:
I am trying to run a program on machine B from machine A. I need to
SSH from A to B, run the program which will ask for a password
interactively, give it the password and then disconnect.

I came across Except but cannot see how to ssh and then inside the ssh
I initiate run the program.

I have written some code with Net::SSH::perl that connects and runs
the program but it asks for the password at my command line and won't
accept it from the program.

Code:
-----------------------------
use Net::SSH::perl;

require '/storage/mu/etc_defaults.pl';

$cmd = $radius_restart_cmd;

my %params = (
protocol => 2,
);

my $ssh = Net::SSH::perl->new($radius_host, %params);
$ssh->login('root', $radius_su);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
---------------------------------------------^^^
From the documentation:

($out, $err, $exit) = $ssh->cmd($cmd, [ $stdin ])

"Runs the command $cmd on the remote server and returns the stdout,
stderr, and exit status of that command."

So try this:

my($stdout, $stderr, $exit) = $ssh->cmd($cmd, 'admin');
my($stdout, $stderr, $exit) = $ssh->cmd('admin');

Then you can get rid of the line above. Basically, you called cmd()
twice and clobbered the return values from the first call. You also
would have seen some important messages if warnings were enabled...

[snip]

HTH- keith
 
K

ko

ko said:
From the documentation:

($out, $err, $exit) = $ssh->cmd($cmd, [ $stdin ])

"Runs the command $cmd on the remote server and returns the stdout,
stderr, and exit status of that command."

the line below that is the most important part...wrong cut and paste:

"If $stdin is provided, it's supplied to the remote command $cmd on
standard input."

[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top