花了几天的时间研究一下Python,终于能折腾出一支可以备份思科设备的脚本。真心佩服那些码农的脑袋瓜。。。以下为备份的脚本
#!/usr/bin/eve python
import pexpect
import sys
import time
import datetime
class CiscoSwitch():
def __init__(self, host, username, password): self.username = username self.host = host self.password = password def Login(self): self.child = pexpect.spawn('telnet '+self.host) self.child.expect('Username:') self.child.sendline(self.username) self.child.expect('Password:') self.child.sendline(self.password) self.child.expect('#') self.child.sendline('terminal length 0') self.child.expect('#') return (self.child, self.child.before) def FtpBackupCmd(self,tftpip): self.child.sendline('copy running-config tftp:') self.child.expect(']?') self.child.sendline(tftpip) self.child.expect(']?') DATE = datetime.datetime.now().strftime('%Y-%m-%d‘) self.child.sendline(DATE+'-'+self.host) self.child.expect('#') return (self.child, self.child.before) if __name__ == '__main__': for ip in open('/opt/other/ip.txt') : Switch = CiscoSwitch(ip,'admin','Password.123') (obj,stdout) = Switch.Login() (obj,stdout) = Switch.FtpBackupCmd('172.16.200.201') print stdout
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦