首页 > 编程语言 > 详细

python远程修改配置文件

时间:2018-06-27 15:36:00      阅读:381      评论:0      收藏:0      [点我收藏+]
#/usr/bin/env python

remote file auto packages and download

import pexpect
import sys

ip = "192.168.1.116"
user = "root"
passwd = "vision"
target_file = "/usr/local/src/1.txt"

child = pexpect.spawn("/usr/bin/ssh", [user+‘@‘+ip])
fout = file(‘/usr/local/src/package.log‘, ‘w‘)
child.logfile = fout

try:
child.expect(‘(?i)password:‘)
child.sendline(passwd)
child.expect(‘#‘)
child.sendline("sed -i ‘s#victor#david#g‘ "+target_file)
child.expect(‘#‘)
child.sendline(‘exit‘)
fout.close()

except EOFError as EOF:
print("EOF")
except Exception as TIMEOUT:
print("TIMEOUT")

python远程修改配置文件

原文:http://blog.51cto.com/victor2016/2133247

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!