python 实现远程主机执行命令函数
2015-03-13 17:46
701 查看
#!/usr/bin/python # coding=utf-8 import os import paramiko \\定义 h_name 远程主机ip h_cmd 执行的命令 def remote_cmd(h_name,h_cmd): sshadd = h_name sshusr = 'root' sshpwd = 'YourPasswd' sshport = 22 sen1 = 'export JAVA_HOME= YourJdkPath ;' sen2 = '命令1;' sen3 = '命令2;' num = '2' \\命令数量 paramiko.util.log_to_file('ssh.txt') ssh = paramiko.SSHClient() known_host="/root/.ssh/known_hosts" ssh.load_system_host_keys(known_host) privatekeyfile = os.path.expanduser('/root/.ssh/id_rsa') mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile,password='密钥密码') ssh.connect(hostname = sshadd, username = sshusr, password = sshpwd, port = sshport) stdin, stdout, stderr = ssh.exec_command('n=' + num + ';' + sen1 + sen2 + sen3 ) return stdout.read().strip('\n')
相关文章推荐
- Python 使用paramiko实现远程登录Linux主机并执行命令和操作
- linux expect实现登陆远程主机并执行命令示例代码
- paramiko模块实现批量执行远程主机命令
- JAVA实现远程执行SSH2主机的SHELL命令
- python使用paramiko模块实现ssh远程命令执行,与sftp文件下载功能
- Python socket套接字实现C/S模式远程命令执行功能案例
- 项目总结(三)----------Python实现SSH远程登陆,并执行命令!
- JSch:纯JAVA实现远程执行SSH2主机的SHELL命令
- python实现Telnet远程登陆到设备并执行命令
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- linux下远程服务器批量执行命令及SFTP上传文件 -- python实现
- Python paramiko模块 实现 ssh远程执行命令 上传下载文件 堡垒机模式下的远程命令执行
- 利用python的paramiko模块,自定义函数远程批量执行shell命令
- Python实现SSH远程登陆,并执行远程命令
- 纯JAVA实现远程执行SSH2主机的SHELL命令
- 项目总结(三)----------Python实现SSH远程登陆,并执行命令!
- shell脚本实现同时多台远程主机执行命令的代码分享
- Python实现SSH远程登陆,并执行命令!
- python paramiko实现多线程远程执行命令、多线程远程上传文件、多线程远程下载文件
- Python实现SSH远程登陆,并执行命令的方法(分享)