#!/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()

相关文章:

  • 2022-12-23
  • 2021-04-14
  • 2022-01-07
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
相关资源
相似解决方案