环境:CentOS 7.X
一、禁用selinux:
#setenforce 0
#sed -i “s/^SELINUX=.*/SELINUX=disabled/” /etc/sysconfig/selinux
二、安装相关软件
#yum install xinetd tftp-server expect telnet mailx
#vi /etc/xinetd.d/tftp(修改两处)
server_args = -s /var/lib/tftpboot -c
disable = no
#chmod o+w /var/lib/tftpboot
#systemctl restart xinetd
#netstat -aun| grep :69 或 #netstat -au| grep tftp
如果启用了防火墙,则还要开放udp 69端口;
#firewall-cmd --permanent --add-service=tftp
#firewall-cmd --reload
三、编写三个脚本,分别是
begin.sh 环境检查,包括tftp服务,上传目录权限,相关软件包,防火墙端口等
loop.sh 循环读取IP,调用backup.exp脚本执行备份操作,最后打包文件
backup.exp 交换机上传配置文件到tftp服务器
#!/bin/sh
#Write by liuyuhui,2018-10
os=$(uname -r | grep -o "el.") >/dev/null 2>&1
if [ "x$os" != "xel6" ] && [ "x$os" != "xel7" ];then
echo "Unrecognizable OS, only support el6 and el7"
exit 1;
fi
rpm -q tftp-server >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "tftp-server is not installed."
echo "try: yum install -y xinetd tftp-server."
echo "then, vi /etc/xinetd.d/tftp, modify two lines:"
echo "server_args = -s /var/lib/tftpboot -c"
echo "disable = no"
echo