I'm trying to execute remote command over ssh. all working well from the ssh connection and also with an other simple cmd command like 'ls'. but, i would like to using ls and grep for a value stored in a variable(ptrn) but i always failed. i tried using:
- cmd="ls -ltrd /export/home| grep %s ptrn"
- cmd="ls -ltrd /export/home| grep" + ptrn
- cmd="ls -ltrd /export/home| grep", ptrn
but no luck ):
my code:
BuildServer = 1.2.3.4
ptrn = "abc"
cmd="ls -ltrd /export/home| grep ptrn"
ssh = subprocess.Popen(["ssh", "%s" % BuildServer, cmd],shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print (ssh)
Can anyone please help me with that?
Thank you all.