ok today i was asked to edit 900 files in a unix system. i was asked to change the ip addresses on all the dns records in bind.
so when i went to see how many domain names there were, there were like 980 pri. files.. ouch
how am i going to do this.. do i have to do this one by one? no, i thought, there's gotta be an easier way tot do this. well im luck because you can search for text and then replace whatever text you want in a file with some simple commands in linux.
so here is my situation. when i open a pri. file in /var/named/chroot/var/named/pri.mydomain.com it looks something like this:
pri.mydomain.com
$TTL 86400
@ IN SOA ns1.webune.com. admin.mydomain.net. (
2006101601 ; serial, todays date + todays serial #
28800 ; refresh, seconds
7200 ; retry, seconds
604800 ; expire, seconds
86400 ) ; minimum, seconds
;
NS ns1.webune.com. ; Inet Address of name server 1
NS ns1.webune.com. ; Inet Address of name server 2
;
www MX 10 ns1.webune.com.
mydomain.net. A 192.168.1.135
www A 192.168.1.135
;;;; MAKE MANUAL ENTRIES BELOW THIS LINE! ;;;;
as you can see my pri files have 192.168.1.135 address, so i want to change it to 192.168.1.112
so i would use these commands for the shell to go look in all my pri file where it find 192.168.1.135 and replace it with 192.168.1.112
Command:
for fl in pri.*; do
mv $fl $fl.old
sed ’s/192.168.1.135/192.168.1.112/g’ $fl.old > $fl
done
This command will make backup copies of the old files
mv $fl $fl.old
sed ’s/192.168.1.135/192.168.1.112/g’ $fl.old > $fl
done
Command WITHOUT MAKING BACKUPS:
for fl in pri.*; do
mv $fl $fl.old
sed ’s/192.168.1.135/192.168.1.112/g’ $fl.old > $fl
rm -f $fl.old
done
mv $fl $fl.old
sed ’s/192.168.1.135/192.168.1.112/g’ $fl.old > $fl
rm -f $fl.old
done
so now when i view the file called pri.mydomain.com it looks like this:
pri.mydomain.com
$TTL 86400
@ IN SOA ns1.webune.com. admin.mydomain.net. (
2006101601 ; serial, todays date + todays serial #
28800 ; refresh, seconds
7200 ; retry, seconds
604800 ; expire, seconds
86400 ) ; minimum, seconds
;
NS ns1.webune.com. ; Inet Address of name server 1
NS ns1.webune.com. ; Inet Address of name server 2
;
www MX 10 ns1.webune.com.
mydomain.net. A 192.168.1.112
www A 192.168.1.112
;;;; MAKE MANUAL ENTRIES BELOW THIS LINE! ;;;;
- that was easy
