#!/usr/bin/perl # # Written by Thomas York # Written to restart OpenVPN when pinging fails # REQUIRED PACKAGES : p5-net-ping # $|=1; use Net::Ping; use POSIX qw/strftime/; use strict; ################### # # ################### # Ping destination my $ping_dst = "8.8.8.8"; # Timeout (in seconds) my $timeout = 5; #################### # # #################### # Main program execution # Create new ping object my $objPing = Net::Ping->new("icmp"); # Continully ping while () { # Ping! if ($objPing->ping($ping_dst, $timeout)) { # Host is alive # print "DEBUG : ".$ping_dst." is alive.\n"; } else { # Host is dead # print "DEBUG : ".$ping_dst." is dead.\n"; # Restart OpenVPN system("service", "openvpn", "restart"); # Wait 15 seconds, to allow routing to come up sleep 15; } # Wait for 5 seconds before looping back around sleep 5; }