문제

I am using python 2.7.6 for scripting

problem statement:- In my script, I have extracted my applicationId in variable say 'appid' at runtime now I have to pass this as variable in SSHClient command to be executed in remote server, in cmd below

ssh_idb = SSHClient(cfg_cluster_ip)
ssh_idb.login_with_password(username=idb_ssh_user,password=idb_ssh_password)
cmd ='ps -ef | grep "Admin|$appid"'
out, err, code = ssh_idb.execute_sudo_command(["%s" % cmd])
print out

It returns blank output [expected value is not being passed in cmd and shell doesn't returns any data] Is there a way to pass local variable value in cmd dynamically ?

도움이 되었습니까?

해결책

This question is very unclear. Do you mean appid is a local variable in your Python script? If so, you need to pass it to the command string:

cmd ='ps -ef | grep "Admin|%s"' % appid
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top