Script to Automatically Detect and Restart Linux PPTP Client

Script to Automatically Detect and Restart Linux PPTP Client

Category : How-to

Get Social!

Linux penguinThe default PPTP client for Linux does not automatically start on boot, or restart on a failed or dropped connection. I have written a short script to ping your VPN server gateway IP address and start the PPTP client if a ping does not succeed.

See my other post if you have not yet set up your PPTP VPN client.

Create this script and make it executable:

vi /root/cron/
chmod +x /root/cron/

Add the below script to the file and change the following attributes for your own values:

  • your-vpn-host-or-ip-address
  • your-vpn-username
  • your-vpn-password


PINGRES=`ping -c 2 $HOST`
PLOSS=`echo $PINGRES : | grep -oP '\d+(?=% packet loss)'`
echo "$DATE : Loss Result : $PLOSS"

if [ "100" -eq "$PLOSS" ];
    echo "$DATE : Starting : $HOST"
    /usr/sbin/pptp pty file /etc/ppp/options.pptp user $PPTPUSER password $PPTPPASS
    echo "$DATE : Now running : $HOST"
    echo "$DATE : Already running : $HOST"

Add the following entry to your cron to execute the script every minute.

crontab -e
 */1  * * * * /root/cron/ >> /var/log/pptp_pinger.log 2>&1

See my other post if you have not yet set up your PPTP VPN client.


Gary Alan Lee

10-Oct-2014 at 12:36 pm

I have tried this a number of times and for some I can’t get it to work on CentOS 5.11….. What am I doing wrong…? I added a pppd Call at the end of my rc.local config file and the vpn starts fine that way on boot but after about 15 or 20 min that darn system drops the VPN connection….. Bummer…!!!! I get a bunch of command errors when I try to fire-up your sh….



    11-Oct-2014 at 11:06 am

    What errors do you get?


18-Dec-2014 at 8:56 pm

ppt supports persist and maxtries to retry forever to reconnect. No need of additional script:


19-Feb-2015 at 2:23 pm


Thanks for the script! i’ve got a quick qeustion. is it possible to use a command in this script for including the site configuration file stored in /etc/ppp/peers and /etc/ppp/chap-secrets ?

Thanks in advance !



25-Jul-2015 at 2:22 pm

For the start-on-reboot issue, I think this should suffice:

$ sudo update-rc.d pptpd defaults

Andres Gregori

15-Sep-2015 at 7:13 pm

In my case, I’ve setting cron from /etc/cron.d/pptp-cron file

How ever in order to works I’ve to put this at beggining file:


*/1 * * * * root /root/cron/ >> /var/log/pptp_pinger.log 2>&1

seems to be a normal bug on Debian:

Nagarjuna Reddy

29-May-2018 at 4:19 pm

Hi i have phased some problems in ppp connection i tried to connection in automatically.
can you please solve that problem . I am using BeagleBoneBlack.


9-Jan-2019 at 10:23 am

can you please tell me is it working on opensuse


22-Jan-2019 at 10:15 am

connect: Network is unreachable
Tue Jan 22 11:37:01 EET 2019 : Loss Result :
/root/cron/ line 11: [: : integer expression expected
Tue Jan 22 11:37:01 EET 2019 : Already running :

line 11 is:
if [ “100” -eq “$PLOSS” ];



15-Aug-2020 at 12:59 pm

I tried your script and it worked perfectly.

Thank you so much.

Leave a Reply

Visit our advertisers

Quick Poll

Are you using

Visit our advertisers