forked from nsdown/eazy-for-ss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenwrt-oc.sh
42 lines (37 loc) · 1002 Bytes
/
openwrt-oc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
cat > /usr/bin/checkvpn <<"END"
#!/bin/sh
if [ -f "/tmp/vpn_status_check.lock" ]
then
exit 0
fi
selfip="\$(wget -q -O - ip.keithscode.com)"
vpnip="\$(resolveip vpn.myserver.com)"
if [ -z "\$(ifconfig | grep openconnect)" ]
then
touch /tmp/vpn_status_check.lock
echo WAN_VPN_RECONNECT at: > /tmp/vpn_status_reconnect.log
date >> /tmp/vpn_status_reconnect.log
ifdown openconnect
sleep 10
ifup openconnect
sleep 30
rm /tmp/vpn_status_check.lock
else
if [ \$selfip = \$vpnip ];
then
date > /tmp/vpn_status_check.log
else
touch /tmp/vpn_status_check.lock
echo WAN_VPN_RECONNECT at: >> /tmp/vpn_status_reconnect.log
date >> /tmp/vpn_status_reconnect.log
ifdown openconnect
sleep 10
ifup openconnect
rm /tmp/vpn_status_check.lock
fi
date > /tmp/vpn_status_check.log
fi
END
chmod a+x /usr/bin/checkvpn
echo '*/5 * * * * /usr/bin/checkvpn' > /etc/crontabs/root
/etc/init.d/cron restart