named hints update script

I need help getting this bourne shell script working properly. This script I found online while reading some tutorials on getting a caching name server running, which is supposed to update the rootserver hints file. The original script is found here: http://tldp.org/HOWTO/DNS-HOWTO-8.html

When I run the command:
[cmd=]dig @e.root-servers.net . ns > root.hints.new 2> errors[/cmd]
outside of the script I get an ambiguous command error.
When I use the command
[cmd=]dig @e.root-servers.net . ns > root.hints.new[/cmd]
I have no troubles. What's the problem here? Is it because it is writing the results to 2 files?

Also the below case statement always returns that the hints file has failed. Even though when I check the file it looks normal and I can see the NOERROR status in the returned header.

Code:
dig @e.root-servers.net . ns >root.hints.new 2> errors

 case `cat root.hints.new` in
   *NOERROR*)
        # It worked
        :;;
   *)
        echo "Subject: The root.hints file update has FAILED."
        echo
        echo "The root.hints update has failed"
        echo "This is the dig output reported:"
        echo
        cat root.hints.new errors
        exit 1
        ;;
 esac

I have also been wanting to turn these case statements into if statements if anyone could help me with the syntax for that. I don't typically like to use case statements when there is usually only 1 or 2 possible results. The problem I'm having here is that I can't seem to put command output into a string/variable. See the code below for an example of my intentions.

Code:
#Code to check if named is running.
status = 'rndc status | grep server'
if [ $status != 'server is up and running' ]
echo "Named is not running!"
echo "Exiting."
exit 0
fi

Maybe it's just me but I think the if statement looks cleaner than the case statement used in the original script.

Extra information:
I'm running this on FreeBSD 8.2-RELEASE.
The caching name server is working with no problems.
 
(t)csh has its own weird way of redirecting output. You'll either have to learn it, or put the command in a /bin/sh script so you can avoid it ;)

[cmd=]man csh | less +/"output of a command may be redirected"[/cmd]
 
DutchDaemon said:
(t)csh has its own weird way of redirecting output. You'll either have to learn it, or put the command in a /bin/sh script so you can avoid it ;)

[cmd=]man csh | less +/"output of a command may be redirected"[/cmd]

Thank you for your response. I will go back and rtfm. Funny part is that command was in a script and after running it outside I realized it was erroring on me.

Still hoping for any help on the script itself.
 
Script is complete.

If anyone is interested here it is:

Code:
#!/bin/sh
#
#Update named hints file
#Make a cron entry and forget about it!

#Check if named is running
echo "Checking if named is running..."

if `rndc status | grep -q "server is up and running"`
then
echo "Named is running!"
else
echo "Named is NOT running!"
echo "Exiting."
exit 0
fi

#Check for internet connection
echo "Checking if we are online..."

if `ping -c 1 <external ip> | grep -q "100.0% packet loss"`;
then
echo "We are not online!"
echo "Could not ping external server!"
echo "Exiting."
exit 1
else
echo "We are online!"
fi

#Create root.hints file

echo "Creating /etc/namedb/root.hints.new..."
dig @a.root-servers.net . ns > /etc/namedb/root.hints.new

if `cat /etc/namedb/root.hints.new | grep -q "NOERROR"`;
then
echo "File creation successful!"
echo "Replacing old file with updated information..."
chmod 644 /etc/namedb/root.hints.new
cp /etc/namedb/root.hints /etc/namedb/root.hints.old
cp /etc/namedb/root.hints.new /etc/namedb/root.hints
rm -f /etc/namedb/root.hints.new
echo "Restarting Named..."
/etc/rc.d/named onerestart
else
echo "The root.hints file update has FAILED!"
echo "Printing dig output..."
cat /etc/namedb/root.hints.new
echo "Exiting."
exit 1
fi

echo "Update Complete!"
exit 0
 
Back
Top