自动备份交换机配置

自动备份交换机配置,第1张

概述自动备份交换机配置

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

#!/usr/bin/env python#Coding:utf-8"""  Author:  EDWard.Zhou -- <[email protected]>  Purpose: 批量自动备份思科交换机配置文件  Created: 2015/5/8"""import sysimport osimport telnetlibimport timeimport threadingimport datetime#Use for loop to telnet into each routers and execute commandsclass Bakconf(threading.Thread):    def __init__(self,host,username,password):        threading.Thread.__init__(self)        self.host=host        self.username=username        self.password=password    def run(self):        try:            tn = telnetlib.Telnet(self.host,port=23,timeout=10)        except:            print "Can't connection %s"% self.host            return        tn.set_deBUGlevel(5)        tn.write(self.username +b"\n")        tn.write("en\n")        tn.write(self.password + b"\n")        tn.write("copy startup-config tftp:\n")        tn.write(tftpser + b"\n")        tn.write(b"\n")        time.sleep(1)        tn.write("exit\n")        tn.close()def main():    username = "**********"    password = "**********"    global tftpser    tftpser="192.168.103.71"    for host in open(r'sw.txt').readlines():        dsthost = host.strip('\n')        bakconf=Bakconf(dsthost,password)        bakconf.start()    #Backup switch config and tar    time.sleep(1)    dtime=datetime.datetime.Now().strftime("%Y%m%d%H%M%s")    os.popen('tar -cjf /backup/cisco/switch-'+dtime+'.tar.bz2 '+ '/tftproot')    os.popen('rm -fr /tftproot/*')    os.popen('find /backup/cisco/ -mtime +90  -exec rm {} \;')if __name__=="__main__":    main()

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的自动备份交换机配置全部内容,希望文章能够帮你解决自动备份交换机配置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1199186.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存