0

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.

Farvardin
  • 5,336
  • 5
  • 33
  • 54
James Shi
  • 1,894
  • 2
  • 13
  • 16
  • 4
    Are you *sure* that the VPN will have started after 3 seconds? (Have you tried increasing that to, say, 10 seconds?) –  Feb 01 '15 at 07:24
  • @duskwuff obviously not. but it doesn't work if i make it little or delete this line – James Shi Feb 01 '15 at 07:36

1 Answers1

0

Altering sleep 3 to sleep 10, it works again. This error caused by network delay.

James Shi
  • 1,894
  • 2
  • 13
  • 16