1

I want to change $PATH environment variable from paramiko SSH session. I tried following code but, it is not changing the path.

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('xxx.xxx.xxx.xxx', username='xxxxxx', password='xxxxxx')
ssh.exec_command("export PATH=/tmp:$PATH")
ssh.exec_command("echo $PATH")

I have a binary file 'sysinfo' which calls other binaries. So, I want to change PATH environment variable to precede all others paths with /tmp directory and place my file in /tmp which that binary file requires, so that it executes it. But its not changing the $PATH. After I check the output of "echo $PATH" it still shows-

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

I also tried appending "export PATH=/tmp:$PATH" in .bashrc file and running "source .bashrc". It didn't work.

And finally I tried running

ssh.exec_command("export PATH=/tmp:$PATH /bin/sysinfo")

And this too didn't work.

bluestorm
  • 21
  • 4
  • What makes you think it's not changing the path? Are you running another command through paramiko? Something that's supposed to benefit from the changed PATH? Please [edit] your question to include all of code that's relevant to your problem. – Kenster May 25 '20 at 15:37
  • @Kenster Thanks. I have edited the question. Please check it out. – bluestorm May 25 '20 at 15:58
  • @MartinPrikryl I did the same thing with both && and ; still its not working – bluestorm May 25 '20 at 16:17
  • Nevermind, Thanks a lot! It worked finally. – bluestorm May 25 '20 at 16:26

0 Answers0