2

this is how my python script looks like

import os
command = 'ssh testServer'
os.system(command)

it gives me following error

[Sun Aug 17 11:07:30 Adam@testServer:~/] $ python test.py
ld.so.1: ssh: fatal: relocation error: file /usr/bin/ssh: symbol SUNWcry_installed: referenced symbol not found
Killed

Ssh command works fine when I execute it from command line. Only when I try it from within a python script using either os/subprocess module, it complains with the above error.

4
  • 1
    The problem seems to be related to the LD_LIBRARY_PATH environment variable. Could you post the output of ldd /usr/bin/ssh and echo $LD_LIBRARY_PATH both from the command line and from a python system call. Commented Aug 17, 2014 at 18:38
  • libsocket.so.1 =>/lib/libsocket.so.1 libnsl.so.1 =>/lib/libnsl.so.1 libz.so.1 =>/opt/svn/current/lib/libz.so.1 libz.so.1 (SUNW_1.1) => (version not found) libcrypto.so.0.9.7 => /usr/sfw/lib/libcrypto.so.0.9.7 libgss.so.1 =>/usr/lib/libgss.so.1 libc.so.1 =>/lib/libc.so.1 libmp.so.2 =>/lib/libmp.so.2 libmd.so.1 =>/lib/libmd.so.1 libscf.so.1 =>/lib/libscf.so.1 libcmd.so.1 =>/lib/libcmd.so.1 libdoor.so.1 =>/lib/libdoor.so.1 libuutil.so.1 => /lib/libuutil.so.1 libgen.so.1 =>/lib/libgen.so.1 libcrypto_extra.so.0.9.7 => /usr/sfw/lib/libcrypto_extra.so.0.9.7 libm.so.2 =>/lib/libm.so.2 Commented Aug 17, 2014 at 18:48
  • echo $LD_LIBRARY_PATH /opt/svn/current/lib Commented Aug 17, 2014 at 18:50
  • and what is $LD_LIBRARY_PATH when running python? Commented Aug 17, 2014 at 18:57

4 Answers 4

1

You shouldn't use os.system, you should use a subprocess:

Like in your case:

 bshCmd = "ssh testServer"
 import subprocess
 process = subprocess.Popen(bshCmd.split(), stdout=subprocess.PIPE)
 output = process.communicate()[0]

Please let me know if you have any questions!

Sign up to request clarification or add additional context in comments.

11 Comments

Hello @cartridgemeadow.. I used both os/subprocess and see the same result. I specified this in my question originally. Just to confirm I used your code but see the same error again
hmm...@user2812714, could you try running "unset $LD_LIBRARY_PATH" before you run ssh; and before you unset it, be SURE to echo it and copy it's contents from bash into a text file, so that you could reset it later
also, if you run "ssh testServer" from bash, does it work? if it does, then this is a python issue that has to do with property settings and we could find a work around!
I get this when I try to unset unset $LD_LIBRARY_PATH -bash: unset: `/opt/svn/current/lib': not a valid identifier
yes as mentioned in the question, it does work when I execute it from bash.
|
1

So your ssh relies on a library that is located in /opt/svn/current/lib: "libz.so.1 =>/opt/svn/current/lib/libz.so.1 libz.so.1 (SUNW_1.1)". It finds this library by looking at the environment variable LD_LIBRARY_PATH. This variable is not preserved by the os.system call in python.

import os
import subprocess
command = 'ssh testServer'
subprocess.Popen(command, shell=True, env=os.environ)

Comments

0

Have you considered using an ssh automation package instead? Something like https://pypi.python.org/pypi/ssh/1.7.8

Comments

0

The os.system has many problems and subprocess is a much better way to executing unix command. Use This recipe:

import subprocess
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],
                           shell=False,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)

2 Comments

I used both subprocess/os as mentioned in the question. I still see the same issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.