shell script help

Steve Buehler steve at ibapp.com
Fri Aug 19 18:23:15 UTC 2005


	I am hoping that someone here can help me with a shell script.  I 
can do this in PHP but am trying to learn how to script better in a 
shell script.
	What I am trying accomplish here is to get all of this into one 
script and do it more efficiently:
1.  Get all db.domainname.extension files in the /var/named directory
2.  Replace any occurance of a line that starts with 
"mail\s\+A\s\+192.168.22[4-5].*" with "mail\t\t\tA\t192.168.1.4"
	2.a.  For testing, I am copying these to another directory first and 
doing all work in the test directory until the script works perfectly.
3.  If the file gets changed, I need it to put the file name without 
the leading "db." into test.txt in the following format:
	to:domainname.extension                   RELAY
4.  If the file already has the line of "mail\s\+A\s\+192.168.1.4" in 
it, then I need it to also put that into the test.txt file in the same format.
	to:domainname.extension                   RELAY
5.  If the file has anything but the "192.168.22[4-5].*" or 
"192.168.1.4" IP's for that line, then I don't want it to change it 
and I don't want to record it in the test.txt file.

This script is going to change all of the dns records so that the 
mail.domainname.extension will point to our new email server.  I want 
to get it automated so that if anybody sets a site up in our Ensim 
control panel, it will make these changes and then I can create a 
script that will move the test.txt file over to the email server in 
an "access" file, then make the access.db and restart 
sendmail/MailScanner.  I will eventually test to see if there are any 
changes in the old and new access files and if not, it won't restart 
sendmail/MailScanner.  I figure that I will run this twice a day.

Right now, I am doing this in two separate scripts and it doesn't do 
everything I want here anyway.
Here is what I have so far:
----start test.sh file----
#!/bin/sh
cp -pf /var/named/db* .
for i in `ls db.*`
do
echo $i
mv $i $i.$$
sed 's/mail\s\+A\s\+192.168.22[4-5].*/mail\t\t\tA\t192.168.1.4/' $i.$$ > $i
rm $i.$$
done
----end test.sh file----

----start test2.sh file----
#!/bin/sh
for i in `ls db.*`
do
echo $i
grep -H 'mail\t\t\tA\t192.168.1.4'
rm $i.$$
done
----end test2.sh file----

Thanks in advance for any help.
Steve




More information about the redhat-list mailing list