zoukankan      html  css  js  c++  java
  • paramiko.SSHClient()的exec_command函数内部如何使用变量

    #!/usr/bin/env python
    #coding: utf-8

    import paramiko
    IP='xxx.xxx.xxx.xxx'
    FILEPATH='/root/test/test'
    LINE= 'user=lalala'
    print(FILEPATH)
    # 建立一个sshclient对象
    ssh = paramiko.SSHClient()
    # 允许将信任的主机自动加入到host_allow 列表,此方法必须放在connect方法的前面
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    # 调用connect方法连接服务器
    ssh.connect(hostname=IP, port=22, username='root', password='1111')
    # 执行命令

    command1="each $LINE"
    command2="each user"
    ####################
    ##问题:
    exec_command
    为何使用变量不行,使用字符串可以   如何调整command1使其也能运行,要使用变量

    ##
    ####################
    stdin1, stdout1, stderr1 = ssh.exec_command(command)
    result1 = stdout1.read().decode('utf-8')
    print(result1)
    print(len(result1))


    # 关闭连接
    ssh.close()
  • 相关阅读:
    厦门大学 ACM 1465 连续数列 三分
    厦门大学 ACM 1437 三分
    南京理工 ACM
    厦门大学 ACM 1466 线段树维护
    LCS N(log (N) )
    hdu 1520
    HDU 2196
    zoj 3710 暴力
    互联网创业盈利模式指南(转)
    map
  • 原文地址:https://www.cnblogs.com/mathprogrammer/p/13051438.html
Copyright © 2011-2022 走看看