LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Script to restart natd and watch it (https://www.linuxquestions.org/questions/programming-9/script-to-restart-natd-and-watch-it-164537/)

rspurlock 03-31-2004 09:18 AM

Script to restart natd and watch it
 
I'm trying to write either a perl script or shell script to restart natd after a php 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.

#!/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

Will this do the trick? The next question is this: How would I then check to make sure it's restarted, and if it hasn't, have it run natd with a backup config file that's know good? (ie /etc/natd.good)

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


All times are GMT -5. The time now is 09:06 AM.