python

stdin, stdout, stderr = client.exec_command('cd /home/someone;mkdir aa')

def remote_modify(mblade):
    client = master_module.get_connection('remote_modify', mblade, port, username1, password1)
    client.exec_command('cd /opt/app/jboss-eap-6.0/standalone/configuration;mv standalone.xml standalone.xml.bak')
    stdin, stdout, stderr = client.exec_command('cd /opt/app/jboss-eap-6.0/standalone/configuration;cat standalone.xml.bak')
    file = ''
    find = 0
    for line in stdout:
        if '''<connector name="http-post" protocol="HTTP/1.1" scheme="http" socket-binding="http-post"''' in line and '/>' in line:
            find += 1
            continue
        if '''<socket-binding name="http-post" port=''' in line and '/>' in line:
            find += 1
            continue
        file = file + line + '
'
    if find!=2:
        print '***********SOMETHING ERROR, Please check standalone.xml!!!'
    file_str = ''
    client.exec_command("cd /opt/app/jboss-eap-6.0/standalone/configuration;echo '" + file + "' > standalone.xml")
    client.close()

  

原文地址:https://www.cnblogs.com/drizzlewithwind/p/5065798.html