Restarting NATD script

Robert Spurlock rspurlock at lock-net.com
Tue Mar 23 20:15:36 PST 2004


I'm trying to write either a perl script or shell script to restart
natd after an html script adds to the natd.conf file.  The problem
I've run into is after the script kills the natd process, it has to
quess how long to wait before it restarts it.  Here's how I'm doing
it now:

#!/usr/bin/perl
##Restart NATD
print `kill \`cat /var/run/natd.pid\``;
sleep (20);
print `/sbin/natd -f /etc/natd.conf`;

I need to run a loop that continuously checks for natd to be killed
before it tries to run again.  Since I'm doing all this remotely it
causes major problems if the timing is off and it tries to restart
but can't.  What would be ideal is if it even checks after the
restart it checks one more time to see if it fails.  If it fails it
could start up with a default backup natd.conf.backup file.

#!/bin/ksh
kill \`cat /var/run/natd.pid\`
while true
do
if [ -z $(ps -ef |grep natd | grep -v grep) ] ; then
    /sbin/natd -f /etc/natd.conf
fi
done
exit

Help completing this script would be great.  Thanks in advance!

Rob

Webmail Provided by Lock-Net Internet Services: www.lock-net.com



More information about the freebsd-questions mailing list