#!/usr/bin/perl
#
# Written by Thomas York
# Written to restart ospfd if routes disappear.
#
while () { # Main program loop
# Get route list
@route_output = `ip route list`;
# Count number the number of routes for 10.0.17.0/24
$count = grep m/10.0.17.0\/24 via/, @route_output;
if ($count == 0) { # The route does NOT exist!
print "No route found for 10.0.17.0/24!\n";
# Restart ospfd
system "service ospfd restart";
print "ospfd restarted\n";
# Sleep for three seconds to allow OSPF routes to populate
sleep 3;
}
sleep 1; # Sleep for 2 seconds before starting the loop again
}