Skip to content
Advertisement

pass commands server using perl openssh

there are 2 systems,

client system, in which i am passing commands to the server by doing openssh to the server and my script goes like this

#!/usr/bin/perl
use lib "/home/geek/app/usr/lib/perl5/site_perl/5.8.8";
use lib "/home/geek/app/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi";
use lib "/usr/lib/perl5/5.8.8";

use Net::OpenSSH;
my $host = '******010';
my $user = '*****';
my $pass = '*****';
my $ssh = Net::OpenSSH->new("$user:$pass@$host");
$ssh->error and
 die "Couldn't establish SSH connection: ". $ssh->error;
my $out = $ssh->capture("/p/inway/bin/inway71 lib123 p123.0_CC default ");
#my $out = $ssh->capture("cd units; ls");
#$out = $ssh->capture("ls units/");

 print "output is $out";

and in server /p/inway/bin/inway71 is a scripts:

#!/bin/sh
. $MODULESHOME/init/sh
module load lsf

exec bsub -Is -q interactive -J INWAY71_LSF -R 'type==X64LIN && osrel==50 && clearcase' /nfs/site/proj/inway/bin/inway71 ${1+"$@"}

so when i login to my server and run this script in my terminal, i will be directed to some path (i have no clue what it is, but i guess its one more server which i can login using this bash script) and i can do the rest of the activity like cd,ls,cat, etc etc)

but when i run this from my client system it passes the control to the terminal and waits for my input, and in my terminal i get an error saying,

stty:standard input:Invalid argument

In my terminal i can do ls or anything, but not able to do it from the perl script and capture the result. How can i resolve this and get what i want?

Advertisement

Answer

That remote command expects to be run in interactive mode. This doesn’t work with the SSH command mode. See this Net::OpenSSH FAQ!

You can:

  1. find a way to pass commands as arguments to that script.
  2. rewrite it to accept commands as arguments.
  3. talk to it using Expect.
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement