如何在exec_command中传递2个字符串变量

时间:2018-04-17 11:39:52

标签: python

import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('hostname', username='test1234', password='test')
path = ['/home/test/', '/home/test1/','/home/test3/']
sftp = client.open_sftp()
check = 'tail -f /home/test/logs/check.out'
for filename in sftp.listdir(path):
    if filename.endswith('.txt'):
        h = path + filename 
        stdin,stdout,stderr = client.exec_command('%s && %s | grep -i "Connection time out"' %path %check)
        stdout = = revout.read().decode().splitlines()
        print stdout

我试图一次将2个字符串传递给exec_command。但它不起作用。 如何一次传递2个字符串?

1 个答案:

答案 0 :(得分:1)

您可以使用

'%s && %s | grep -i "Connection time out"' % (path,check)

或Python 3的.format

'{0} && {1} | grep -i "Connection time out"'.format(path,check)