cosmicsoup has asked for the wisdom of the Perl Monks concerning the following question:

Monks,
Again I find myself needing your wisdom. I am trying to use Net::SSH::perl to execute multiple commands. It's not working.
my $ssh = Net::SSH::Perl->new("mybox.myhost.com"); $ssh->login($user, $pass); $ssh->cmd( "export SYBASE=\"/usr/local/sybase/OC\"" ); $ssh->cmd( "export AUTOSYS=\"/usr/platinum/autosys\"" ); $ssh->cmd( "export AUTOUSER=\"/usr/platinum/autouser\"" ); $ssh->cmd( "export __std_err_file=/dev/null"); $ssh->cmd( "export __command=NIL"); $ssh->cmd( "export AUTO_JOB_PID=0"); $ssh->cmd( "export AUTO_JOB_NAME=\"myjob\""); $ssh->cmd( "export APP_ROOT="); my($stdout, $stderr, $exit)=$ssh->cmd( "autorep -q -J myjob#init#t" ); print "$stdout\n";

When this script actually runs, I get an error message basically telling me that all my exports above did not take place, because it can't find sybase. Anyone know what I am doing wrong?

Thanks!

2006-04-22 Retitled by Corion, as per Monastery guidelines
Original title: 'Net::SSH::perl'

Replies are listed 'Best First'.
Re: use Net::SSH::perl to execute multiple commands
by zengargoyle (Deacon) on Feb 21, 2003 at 22:56 UTC

    is it possible that each call of cmd uses a new instance of your shell? try doing it all in one big command

    my $cmd = <<_COMMANDS_; export SYBASE="/usr/local/sybase/OC" export AUTOSYS="/usr/platinum/autosys" export AUTOUSER="/usr/platinum/autouser" export __std_err_file=/dev/null export __command=NIL export AUTO_JOB_PID=0 export AUTO_JOB_NAME="myjob" export APP_ROOT= autorep -q -J myjob#init#t _COMMANDS_ ... $ssh->cmd($cmd);

    if nothing else it's easier on the eyes.

Re: use Net::SSH::perl to execute multiple commands
by runrig (Abbot) on Feb 22, 2003 at 08:36 UTC
    Are you connecting with SSH protocol 1 or 2? Try to connect with 2 if you can. Or see if you can send all the commands at once as already suggested.