0

I'm using paramiko on my local to ssh into a unix server. There is an executable file that I would like to launch from my local on the server. The executable currently fails from local/paramiko because the LD_LIBRARY_PATH environment variable isn't set correctly when I ssh using paramiko, however it's set automatically when I use putty and work interactively. When I log into the machine via putty, the executable file works as expected, but when I log in via paramiko from my local, the exectuable returns an error rleated to the LD_LIBRARY_PATH environment not being set correctly.

When I log into the machine using putty, an admin .login file specifies a series of paths for variable LD_LIBRARY_PATH. It looks like this:

setenv LD_LIBRARY_PATH path1:path2:path3:...

However, when logging in via paramiko, this admin script isn't initiated, and I need to manually set the LD_LIBRARY_PATH variable.

My connection looks like:

ssh = pk.SSHClient()
ssh.set_missing_host_key_policy(pk.AutoAddPolicy())
ssh.connect(hostname='server', username='user', password='password')

The command I want to run looks like:

stdin, stdout, stderr = ssh.exec_command('nohup executablefile')

How can I set my LD_LIBRARY_PATH and then execute my program using paramiko's exec_command, or should I be looking for a different function?

Lisle
  • 1,620
  • 2
  • 16
  • 22
  • Particularly, see [my answer](https://stackoverflow.com/a/31966441/850848). – Martin Prikryl Dec 22 '17 at 17:12
  • I disagree, in that changing the get_pty parameter results in no change (still receiving environment path error). I also do not understand how to implement the ssh -T myuser@host solution when using ssh.connect - is that in option for shh.connect? The startup files are setup correct for interactive putty use, but I can't get paramiko to ssh in like putty does. – Lisle Dec 22 '17 at 17:27
  • So then we need to know a way more. Which of these work: `ssh -T user@host nohup executablefile`, `ssh user@host nohup executablefile`? – Martin Prikryl Dec 22 '17 at 17:31
  • Edited, I'll give you any information I can. – Lisle Dec 22 '17 at 17:36
  • Do you still find this to be a duplicate question? I think the both the scenario and solution are distinct from the other. – Lisle Dec 22 '17 at 17:57
  • You didn't answer my question. – Martin Prikryl Dec 22 '17 at 20:24

2 Answers2

0

I tinkered and found a simple solution.

One can tell remote machine explicitly what the environment path should be via ssh.connect(). The trick is to just tie a series of commands together using ;.

stdin, stdout, stderr = ssh.exec_command('cd directory_desired; setenv LD_LIBRARY_PATH library_path_needed; nohup executable_file')
Lisle
  • 1,620
  • 2
  • 16
  • 22
0

It's likely setting the variable before the command might work. This is for illustration only. This would need to be translated into the equivalent for paramiko.

ssh remote-host 'COOKS=32 env'

Should return something like the following. Which is the contents of the environment from the remote host.

COOKS=32
XDG_SESSION_ID=889
SHELL=/bin/bash
....
0x00
  • 141
  • 2
  • 10