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

You could try some easier path like '/' first and work your way up if that succeeds. One possibility would be some invisible characters in your path string, that can happen if you read that path from a file, for example

PS: What ahmad meant with 'Show us your code' was more along a minimal runnable script that exhibits the problem. Then someone here could run your script with a different ssh-server and report if the script basically works or not

  • Comment on Re: Net::OpenSSH can't change working directory

Replies are listed 'Best First'.
Re^2: Net::OpenSSH can't change working directory
by josh803316 (Beadle) on Jul 16, 2010 at 21:57 UTC
    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";

      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.
      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.