久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

解決Python paramiko 模塊遠程執行ssh 命令 nohup 不生效的問題

瀏覽:86日期:2022-07-17 14:26:00

Python - paramiko 模塊遠程執行ssh 命令 nohup 不生效的問題解決

1、使用 paramiko 模塊ssh 登陸到 linux 執行nohup命令不生效

# 執行命令def command(ssh_config, cmd, result_print=None, nohup=False): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=ssh_config.hostname, port=ssh_config.port, username=ssh_config.username,password=ssh_config.password) print(ssh_config.hostname + ’@’ + ssh_config.username, ’: ’, cmd) stdin, stdout, stderr = ssh.exec_command(cmd) result = stdout.read() if result_print: lines = read_unicode(result) for line in lines: print(line) ssh.close()

因為執行完畢后,shell 會立即關閉通道

2、稍作修改,使用 invoke_shell

# 執行命令def command(ssh_config, cmd, result_print=None, nohup=False): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=ssh_config.hostname, port=ssh_config.port, username=ssh_config.username,password=ssh_config.password) print(ssh_config.hostname + ’@’ + ssh_config.username, ’: ’, cmd) if nohup: cmd += ’ & n ’ invoke = ssh.invoke_shell() invoke.send(cmd) # 等待命令執行完成 time.sleep(2) else: stdin, stdout, stderr = ssh.exec_command(cmd) result = stdout.read() if result_print: lines = read_unicode(result) for line in lines:print(line) ssh.close()

到此這篇關于解決Python paramiko 模塊遠程執行ssh 命令 nohup 不生效的問題的文章就介紹到這了,更多相關Python paramiko 模塊遠程執行ssh 命令 nohup 不生效內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 国产精品久久久久久久岛一牛影视 | 国产激情视频在线观看 | www.久久| 在线一级电影 | 超碰人人99 | 国产精品视频入口 | 九一亚洲精品 | www.99精品| 性大毛片视频 | 久久www免费人成看片高清 | 夜夜久久 | 欧美激情欧美激情在线五月 | 国产精品久久99 | 亚洲免费视频网站 | 国产福利91精品一区二区 | 国产成人精品午夜视频' | 91操操| 亚洲精品视频在线 | 可以在线观看的黄色 | 色视频www在线播放国产人成 | 久久久久一区二区 | 亚洲美女在线视频 | 夜夜艹| 欧美日韩一区二区不卡 | 国产精品美女久久久久久免费 | 看一级黄色大片 | 欧美日韩在线播放 | 一二区视频 | 日韩精品视频在线 | 亚洲一区视频在线 | 日本乱偷中文字幕 | 中文字幕一区二区三区精彩视频 | 黄色高清视频在线观看 | 亚洲精品国产区 | 欧美日韩视频在线观看一区 | 在线观看日韩av | 国产成人综合网 | 久久91| 在线久草| 成人亚洲电影 | 91中文在线 |