0
#!/usr/bin/env python3.5

import subprocess

import os

command=r'ssh <some-server> "(echo \"import os\" ; echo \"for r,d,f in os.walk('/etc/'): print (r,len(f))\")| python"'

ssh=subprocess.call(["bash","-c","{0}".format("command")])
print(ssh)

I'm trying to run the above code and the code gives the following error :

Traceback (most recent call last): File "./test_filelist.py", line 11, in command=r'ssh "(echo \"import os\" ; echo \"for r,d,f in os.walk('/etc/'): print (r,len(f))\")| python"' NameError: name 'etc' is not defined

How do I fix that , Is there something that I need to escape . Thanks in advance .

1 Answer 1

0

You are not escaping correctly your os.walk('/etc/')

Try with:

os.walk(\"/etc/\")
Sign up to request clarification or add additional context in comments.

1 Comment

The error is gone now , but for some reason the code seems to be giving no o/p .

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.