When I executing them sequentially, it works. After I combine them, there comes an error.
The first file(a.sh).
# !/bin/bash
/etc/init.d/xl2tpd start | xargs echo
echo "c zju_vpn" > /var/run/xl2tpd/l2tp-control
The second file(b.sh).
#!/bin/bash
sleep 3
VPN_SERVER_IP=10.5.1.7
DEFAULT_GW=10.214.16.1
route add $VPN_SERVER_IP gw $DEFAULT_GW eth0
route del default
route add default ppp0
ping github.com
After echo "c zju_vpn" > /var/run/xl2tpd/l2tp-control
has been executed, the ppp0 interface will not appear at once. So I write this sleep 3
in file b.sh.
If I combine them into one(c.sh).
#!/bin/bash
/etc/init.d/xl2tpd start
echo "c zju_vpn" > /var/run/xl2tpd/l2tp-control
sleep 3
VPN_SERVER_IP=10.5.1.7
DEFAULT_GW=10.214.16.1
route add $VPN_SERVER_IP gw $DEFAULT_GW eth0
route del default
route add default ppp0
ping github.com
There comes the error: SIOCADDRT: No such device.
There is no ppp0, when I typed ifconfig
. So when execute route add default ppp0
, it will be failed, and this is the reason. But I DON'T know why this happened.
Somebody helps me. Thanks.