自动生成cisco标准配置

#!/bin/bash
while true;do
read -p "请输入运营商接入类型[static/pppoe]:" access_mode
if [ $access_mode == "pppoe" ];then
	read -p "请输入ADSL账号:" pppoe_username
	read -p "请输入ADSL密码:" pppoe_password
	read -p "请输入CE端内网IP地址网络号:" lan_network
        read -p "请输入CE端内网子网掩码:" lan_netmask
        read -p "请输入CE端内网IP网关:" lan_gw
        read -p "请输入CE端内网dhcp保留ip地址至多少:" dhcp_excl_addr
        read -p "请输入CE端针对深圳的tunnel ID:" sz_tunn_id
        read -p "请输入深圳PE端tunnel IP:" sz_pe_tunn
        read -p "请输入CE端针对深圳的tunnel IP:" sz_ce_tunn
        read -p "请输入CE端针对大连的tunnel ID:" dl_tunn_id
        read -p "请输入大连PE端tunnel IP:" dl_pe_tunn
        read -p "请输入CE端针对大连的tunnel IP:" dl_ce_tunn
	read -p "请输入运营商[ct/cnc]:" server_provider
	if [ $server_provider == "ct" ];then
		cp /root/branch_ce_configure/pppoe/ce-ct-pppoe.log.bak /root/branch_ce_configure/auto-con
figure/ce-ct-pppoe.log
		pppoe_path="/root/branch_ce_configure/auto-configure/ce-ct-pppoe.log"
	elif [ $server_provider == "cnc" ];then
		cp /root/branch_ce_configure/pppoe/ce-cnc-pppoe.log.bak /root/branch_ce_configure/auto-co
nfigure/ce-cnc-pppoe.log
		pppoe_path="/root/branch_ce_configure/auto-configure/ce-cnc-pppoe.log"
	else
		echo "输入有误,请重新输入..."
		continue
	fi	
	sed -i "s/lan_network/$lan_network/g" $pppoe_path		
	sed -i "s/lan_gw/$lan_gw/g" $pppoe_path		
	sed -i "s/lan_netmask/$lan_netmask/g" $pppoe_path		
	sed -i "s/dhcp_excl_addr/$dhcp_excl_addr/g" $pppoe_path		
	sed -i "s/sz_tunn_id/$sz_tunn_id/g" $pppoe_path		
	sed -i "s/dl_tunn_id/$dl_tunn_id/g" $pppoe_path		
	sed -i "s/sz_ce_tunn/$sz_ce_tunn/g" $pppoe_path		
	sed -i "s/sz_pe_tunn/$sz_pe_tunn/g" $pppoe_path		
	sed -i "s/dl_ce_tunn/$dl_ce_tunn/g" $pppoe_path		
	sed -i "s/dl_pe_tunn/$dl_pe_tunn/g" $pppoe_path		
	sed -i "s/pppoe_username/$pppoe_username/g" $pppoe_path		
	sed -i "s/pppoe_password/$pppoe_password/g" $pppoe_path
	echo "配置已生成"
	break		
elif [ $access_mode == "static" ];then
	read -p "请输入提供的公网IP:" static_ip
	read -p "请输入提供的公网子网掩码:" static_netmask
	read -p "请输入提供的公网网关:" static_gw
        read -p "请输入CE端内网IP地址网络号:" lan_network
        read -p "请输入CE端内网子网掩码:" lan_netmask
        read -p "请输入CE端内网IP网关:" lan_gw
        read -p "请输入CE端内网dhcp保留ip地址至多少:" dhcp_excl_addr
        read -p "请输入CE端针对深圳的tunnel ID:" sz_tunn_id
        read -p "请输入深圳PE端tunnel IP:" sz_pe_tunn
        read -p "请输入CE端针对深圳的tunnel IP:" sz_ce_tunn
        read -p "请输入CE端针对大连的tunnel ID:" dl_tunn_id
        read -p "请输入大连PE端tunnel IP:" dl_pe_tunn
        read -p "请输入CE端针对大连的tunnel IP:" dl_ce_tunn
	read -p "请输入运营商[ct/cnc]:" server_provider
	if [ $server_provider == "ct" ];then
		cp /root/branch_ce_configure/static/ce-ct-static.log.bak /root/branch_ce_configure/auto-c
onfigure/ce-ct-static.log
		static_path="/root/branch_ce_configure/auto-configure/ce-ct-static.log"
        elif [ $server_provider == "cnc" ];then
		cp /root/branch_ce_configure/static/ce-cnc-static.log.bak /root/branch_ce_configure/auto-
configure/ce-cnc-static.log
		static_path="/root/branch_ce_configure/auto-configure/ce-cnc-static.log"
	else
		echo "输入有误,请重新输入..."
		continue
	fi	
                sed -i "s/lan_network/$lan_network/g" $static_path
                sed -i "s/lan_gw/$lan_gw/g" $static_path
                sed -i "s/lan_netmask/$lan_netmask/g" $static_path
                sed -i "s/dhcp_excl_addr/$dhcp_excl_addr/g" $static_path
                sed -i "s/sz_tunn_id/$sz_tunn_id/g" $static_path
                sed -i "s/dl_tunn_id/$dl_tunn_id/g" $static_path
                sed -i "s/sz_ce_tunn/$sz_ce_tunn/g" $static_path
                sed -i "s/sz_pe_tunn/$sz_pe_tunn/g" $static_path
                sed -i "s/dl_ce_tunn/$dl_ce_tunn/g" $static_path
                sed -i "s/dl_pe_tunn/$dl_pe_tunn/g" $static_path
                sed -i "s/static_ip/$static_ip/g" $static_path
                sed -i "s/static_netmask/$static_netmask/g" $static_path
                sed -i "s/static_gw/$static_gw/g" $static_path  
		echo "配置已生成"
		break
else
	echo "输入有误,请重新输入..."
fi		
done

  

posted @ 2020-03-16 13:50  Me-lihu  阅读(2)  评论(0编辑  收藏  举报