0

I have the following python script which is trying to get file count in every sub-directory under the given path , but it gives no output :

#!/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(\"/home/vibhora/\"): print (r,len(f))\")| python"'
ssh = subprocess.Popen(["bash", "-c", "{0}".format("command")], stdout=subprocess.PIPE)
out = ssh.stdout.read().decode('utf-8')
print(out)

Anybody has any idea what Am I doing wrong here ? Any better approach to get the file list are most welcome , Thanks in advance.

3
  • checkout this question stackoverflow.com/questions/4417546/… Commented Sep 26, 2017 at 7:01
  • Nope , Still doesn't seem to work . Commented Sep 26, 2017 at 7:08
  • have you tried debugging it? Try running 'ssh <some-server>.......' from the commandline and see what you get. Commented Sep 26, 2017 at 7:58

1 Answer 1

1

You are using "command" instead of command.

ssh = subprocess.Popen(["bash", "-c", "{0}".format(`command`)], stdout=subprocess.PIPE`, stderr=subprocess.STDOUT`)
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.