使用expect和cvs来给华为设备做配置比较_硬件维护教程-查字典教程网
使用expect和cvs来给华为设备做配置比较
使用expect和cvs来给华为设备做配置比较
发布时间:2016-12-26 来源:查字典编辑
摘要:以前一只用rancid来对cisco的设备做配置比较,但显然rancid对华为不太友好,一直就不支持华为设备(包括h3)。因此呢,由于本人还...

以前一只用rancid来对cisco的设备做配置比较,但显然rancid对华为不太友好,一直就不支持华为设备(包括h3)。因此呢,由于本人还有点小聪明,知道rancid是考expect和cvs来实现的,于是乎自己写了些比较笨的脚本来给华为的设备做配置比较。

1)去华为设备抓配置

#!/usr/local/bin/expect

spawntelnetx.x.x.x

expect"sername:"

send"xxxxn"

expect"assword:"

send"xxxxn"

expect">"

send"sun"

expect"assword:"

send"xxxxn"

expect">"

send"discun"

log_file/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

while(1){

expect{

"More----"{send""}

"1>"{

send"quitn"

exit

}

}

}

2)把配置中的换行符和敏感信息去掉

cd/tmp/rancid.tmp

rm/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

/home/rancid/huawei/d-cp-ne20-1.sh

cd/tmp/rancid.tmp/Distribution/configs

tr-d'r'</tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

sed-e's/----More.{57}//g'/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

sed-e's/dcipher.{25}/dcipher******/g'/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

sed-e's/simple.*/simple******/g'/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

sed-e's/local-user.*/local-user*****/g'/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

3)把配置加入rancid的cvs中

cvsaddd-cp-ne20-1

cvscommit-mupdates

4)把以下内容做成一个文件加入cron就ok了

cd/tmp/rancid.tmp

rm/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

/home/rancid/huawei/d-cp-ne20-1.sh

cd/tmp/rancid.tmp/Distribution/configs

tr-d'r'</tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

sed-e's/----More.{57}//g'/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

sed-e's/dcipher.{25}/dcipher******/g'/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

sed-e's/simple.*/simple******/g'/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

sed-e's/local-user.*/local-user*****/g'/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1>/tmp/rancid.tmp/d-cp-ne20-1.tmp

mv/tmp/rancid.tmp/d-cp-ne20-1.tmp/tmp/rancid.tmp/Distribution/configs/d-cp-ne20-1

cvscommit-mupdates>/dev/null

btw:关于cvs在web上的显示,我使用的上viewvc,感觉比cvsweb要好哦。还有,不要说俺的脚本写的很烂,俺是学网络的,脚本这东西,现学现用,凑合了。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新硬件维护学习
    热门硬件维护学习
    实用技巧子分类