码迷,mamicode.com
首页 > 编程语言 > 详细

python远程修改配置文件

时间:2018-06-27 15:39:36      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:visio   ges   exception   imp   except   python远程   exce   tor   expect   

#/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远程修改配置文件

标签:visio   ges   exception   imp   except   python远程   exce   tor   expect   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!