In the ordinary work need to back up the switch configuration regularly, if a manual backup, the workload is very large, there is no good tool to reduce the workload of our backup? After searching for data, it is found that expect scripts can be used to implement, expect can interact with the shell to enable the Linux shell to support interaction. Allows us to log on to the server and network devices to perform routine work and batch processing operations.
The whole idea: we use scripts to log in to the switch to execute commands to save the configuration file to the TFTP server, so we need to expect the environment and prepare the TFTP server.
I. Preparation of the Expect environment
Operating system: Centos 6.3 Minimal Installation
[Root@game-syslog-o/]# yum-y Install expect #安装expect +TCL environment
[Root@game-syslog-o/]# yum-y Install openssh-clients #安装openssh
#我这里的环境登录交换机是采用ssh登录所以需要安装
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Network/jhjs/
Ii. preparation of the TFTP server
Change TFTP configuration file
[Root@game-syslog-o/]# yum-y Install tftp tftp-server #安装tftp软件 to store configuration files
[Root@game-syslog-o/] #mkdir/opt/tftp #建立tftp目录
[Root@game-syslog-o/] #chmod 777–r/opt
[Root@game-syslog-o/]# vi/etc/xinetd.d/tftp #编辑配置文件
Service TFTP
{
Socket_type = Dgram
protocol = UDP
Wait = yes
user = root
Server =/USR/SBIN/IN.TFTPD
Server_args =-s/opt/tftp-c
Disable = no
Per_source = 11
CPS = 100 2
Flags = IPV4
}
#指定tftp目录并启用
[Root@game-syslog-o/]#/etc/init.d/xinetd Restart #重启xinetd服务
Close Iptables
[Root@game-syslog-o/] #servive iptables stop
Close SELinux
[Root@game-syslog-o/]# Vi/etc/selinux/config
Selinux=disable
#重启生效
All the preparations have been done, so let's take a look at the script.
To be Continued ~
This article from the "Wang 11" blog, please be sure to retain this source http://wangshiyi.blog.51cto.com/703685/1122154