in reply to Re: Net::OpenSSH can't change working directory
in thread Net::OpenSSH can't change working directory

Sorry, it's part of a large application I'm building so I dummed it down to a simple test:
#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; my $username = 'user'; my $password = 'password'; my $params; $params->{cmd} = "cd /home/user/scripts"; my $session_obj; $session_obj = Net::OpenSSH->new("x.x.x.x", user => $username, passwor +d => $password, strict_mode => 0,master_opts => [ -o => "StrictHostKe +yChecking=no"]); $session_obj->error and die "ssh failed: " . $session_obj->error; my ($out,$err) = $session_obj->capture2({timeout => 30}, $params->{cmd +}); print "THE OUT IS $out\nTHE ERROR IS $err\n";

Replies are listed 'Best First'.
Re^3: Net::OpenSSH can't change working directory
by jethro (Monsignor) on Jul 17, 2010 at 02:29 UTC

    Tried your code and it worked. I used 'cd /usr/local/bin; ls' and got the expected listing

    You haven't said if you tried 'cd /' or something else like 'ls' as commands. Did that work or not?

    The FAQ of Net::OpenSSH informs us that the module uses ssh in command mode, i.e. it logs in for each new command string. Using Expect together with Net::OpenSSH or other ssh modules is offered as a solution, it should use interactive mode.

    You could also just join commands together with ';', for example "cd /usr/local/bin; ls; mv $somefile $otherfile". Low-tech but simple.

      Thanks for the advice and yes I agree, my local script works as well and I noticed that if I separate the command strings they run independently just as you suggested. The solution will be for me to join the commands into a complete set and then figure out a way to group the results. Thank you again for the suggestions and advice.
Re^3: Net::OpenSSH can't change working directory
by josh803316 (Beadle) on Jul 16, 2010 at 22:30 UTC
    It seems that I have two different problems. The first problem is how do I get successive commands to work as if the user is inside the shell or pseudo terminal. If I used the above script and add a second capture line after the first with the command "pwd" I still see the directory as /home/user which means each command is unique to the home directory. So I guess I need to know how to combine command sets........the 2nd error is the bash cd error, but I don't see that same error with my small local script.