0

I am trying to scp a file from my local linux machine to a remote linux machine. Here is the code that i am trying

filename = '/tmp/myfile'
remotepath = '/tmp'
command = 'nodeattr'
sproc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
server = sproc.communicate()

print "connecting to",server[0]

p = subprocess.Popen(["scp", filename, "root@"+server[0]+":"+remotepath])
sts = p.wait()

When I run the above, I get an error as below

connecting to abc.local

ssh: Could not resolve hostname abc.local : Name or service not known
lost connection

However, when I do a ssh on command line, it allows me to connect to the remote host abc.local and I don't have an issue. But when I am using subprocess, I am getting this error.

Any idea if I am using the subprocess in a wrong way?

1 Answer 1

1

Notice the line break between "abc.local" and the following colon in the error message: the actual string you got back from the first Popen is "abc.local\n". You need to .strip() or otherwise get rid of that newline character.

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

Comments

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.