|Keep It Simple, Stupid|
Re: Switch user command not working user Net:SSH2 moduleby salva (Abbot)
|on Oct 29, 2013 at 09:21 UTC||Need Help??|
Net::SSH2 runs every command in a different shell session. Read the FAQ entry "Can't change working directory" from the Net::OpenSSH docs for a more detailed explanation.
There are two ways to do what you want:
One is to start a shell on the remote shell and then simulate an interactive dialogue with it (usually, you use Expect for that, though Expect doesn't work on Windows*). This is hard and error prone, as you will have to look into the command output for the prompt in order to detect when some command is done.
The other way is to combine the sequence of commands into a single one. But, su usually asks for the password and so you will have to send it through its tty.
An easier way is to use sudo, that can be configured to not ask for a password, or alternatively, in recent versions, to get the passwords from stdin. For instance, using Net::SSH::Any:
*) unless you use the perl from Cygwin.