#!/usr/bin/perl use strict; use warnings; # Path to your Neverwinter Nights installation: my $path = "/usr/local/games/nwn/"; # Don't change these two lines! my $pid_file = $path . ".nwnpid"; my $server = $path . "nwserver"; # Time to wait (in seconds) before checking to see if the server is still alive: my $delay = 300; while(1) { # Get the PID of the server my $pid = `cat $pid_file`; chomp($pid); # Get the list of PIDs from Unix my $pid_list = `/sbin/pidof nwserver`; chomp($pid_list); # Get the lowest PID in the list $pid_list = substr($pid_list,rindex($pid_list," ") + 1,length($pid_list) - rindex($pid_list, " ")); # If two aren't equal, restart server if($pid ne $pid_list) { my $now = localtime(); print "Restarting server. . . "; system("$server > /dev/null"); print "done (", $now, ")\n"; } # Go to sleep and try again later sleep($delay); }