#!/bin/sh
log_file=/home/infra_123/eip_vpn/EIP_replace.log
tfstate=/home/infra_123/eip_vpn/terraform.tfstate
ipfile=/home/infra_123/eip_vpn/iplist
mailfile=/home/infra_123/eip_vpn/mailfile.txt
echo "" >> $log_file
echo `date` >> $log_file
rm $mailfile
#sit and uat, tcp 443 port
while read line; do
attach=`echo $line|awk -F ' ' '{print $1}'`
eip=`echo $line|awk -F ' ' '{print $2}'`
clbins=`echo $attach|sed -e 's/_lb//g'`
echo -e '\x1dclose\x0d' | telnet $eip 443
if [ $? == 1 ] ; then
cd /home/infra_li.jun/eip_vpn/
./terraform12 destroy -target=module.modules.tencentcloud_clb_instance.$clbins -auto-approve
./terraform12 apply -target=module.modules.tencentcloud_clb_attachment.$attach -auto-approve
newip=`./terraform12 state show module.modules.tencentcloud_clb_instance.$clbins|egrep -o "\b(12[89]|1[3-8][0-9]|19[01])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}\b"`
sed -i "s/$eip/$newip/g" $ipfile
sleep 5
#check if the new ip is ok
echo -e '\x1dclose\x0d' | telnet $newip 443
if [ $? == 1 ] ; then
echo "$line is NG! Replace with new ip $newip(NG, please check the server!)" >> $log_file
echo "$line is NG! Replace with new ip $newip(NG, please check the server!)" >> $mailfile
else
echo "$line is NG! Replace with new ip $newip(OK)" >> $log_file
echo "$line is NG! Replace with new ip $newip(OK)" >> $mailfile
fi
else
echo "$line is OK" >> $log_file
echo "$line is OK" >> $mailfile
fi
done < $ipfile
#prod, udp 1194 port
cd /home/infra_123/eip_vpn/
prodipfile=/home/infra_123/eip_vpn/prodiplist
line_p=`cat $prodipfile`
attach_p=`echo $line_p|awk -F ' ' '{print $1}'`
eip_p=`echo $line_p|awk -F ' ' '{print $2}'`
clbins_p=`echo $attach_p|sed -e 's/_lb//g'`
result_p=`python3 prod_vpn.py -p 1194 --tls-auth ta.key $eip_p`
echo -e $result_p|grep OK
if [ $? == 1 ] ; then
./terraform12 destroy -target=module.modules.tencentcloud_clb_instance.$clbins_p -auto-approve
./terraform12 apply -target=module.modules.tencentcloud_clb_attachment.$attach_p -auto-approve
newip_p=`./terraform12 state show module.modules.tencentcloud_clb_instance.$clbins_p|egrep -o "\b(12[89]|1[3-8][0-9]|19[01])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}\b"`
sed -i "s/$eip_p/$newip_p/g" $prodipfile
result_p=`python3 prod_vpn.py -p 1194 --tls-auth ta.key $newip_p`
echo -e $result_p|grep OK
if [ $? == 1 ] ; then
echo "$line_p is NG! Replace with new ip $newip_p(NG, please check the server!)" >> $log_file
echo "$line_p is NG! Replace with new ip $newip_p(NG, please check the server!)" >> $mailfile
else
echo "$line_p is NG! Replace with new ip $newip_p(OK)" >> $log_file
echo "$line_p is NG! Replace with new ip $newip_p(OK, udp 1194)" >> $mailfile
fi
else
echo "$line_p is OK" >> $log_file
echo "$line_p is OK(udp 1194)" >> $mailfile
fi
#mail addresses list
mail -s 'VPN ipaddress update' mailaddress@123.com < $mailfile
自动检测公网ip可用性并替换不可用的
于 2021-05-28 13:26:48 首次发布