av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:121日期: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 編程
相關文章:
主站蜘蛛池模板: 亚洲三区在线 | 精久久 | 国产精品一区二区av | 久久亚洲精品国产精品紫薇 | 成人在线电影网站 | 久久免费视频网 | 国户精品久久久久久久久久久不卡 | 99久久精品视频免费 | 日本久久久久久 | 欧美日韩视频在线 | 一级毛片视频 | 亚洲一区二区三区在线视频 | 国产视频福利一区 | 亚洲美乳中文字幕 | 日韩在线观看一区 | 欧美精品一区二区三区在线 | 中国美女撒尿txxxxx视频 | 无人区国产成人久久三区 | 午夜精品影院 | 超碰97免费 | 国产日韩欧美在线播放 | 国产精品久久久久久久久久免费看 | 午夜免费电影 | 亚洲国产精品第一区二区 | 手机看片1| 亚洲精品欧美 | 色狠狠一区 | 91精品久久久久 | 自拍 亚洲 欧美 老师 丝袜 | 欧美偷偷操 | 黄色av网站在线观看 | 日本亚洲欧美 | 一区二区三区不卡视频 | 在线播放国产一区二区三区 | 99综合| 欧美不卡视频 | 欧美日韩成人影院 | 天天操网| 亚洲一区二区三区视频免费观看 | 午夜影院在线观看 | 毛片软件 |