Hi All,
I need a simple script that will help me batch process files.
Input and processing is:
/var/named/subdomain101.domain.tld.db
/var/named/subdomain102.domain.tld.db
/var/named/subdomain103.domain.tld.db
/var/named/subdomain104.domain.tld.db
/var/named/subdomain105.domain.tld.db
...
I have an IP of 1.2.3.4 in all of them and I need to
process them to change the ip to 2.2.2.2
Note, I want to process the files from a list in file.
however, I'm lazy
, so I want to pull in just the subdomain
number.
102
103
104
etc...
I don't want to write the full name.
I want the script to loop and grab the number.
For now (and for the next 12 months) it is going to be 3 digit numbers, running up to 999.
Note: we have already converted the
/var/named/subdomain10.domain.tld.db (just ten)
/var/named/subdomain20.domain.tld.db (just twenty)
and we don't want to modify those.
I grabbed a conversion script from a diff prog, but cant' get it to work on "files in the directory", so batch processing it using an input file has not been explored yet.
PHP Code:
#!/bin/sh
#usage:
# $0 <oldip> <newip>
OLD_IP=$1
NEW_IP=$2
swapfile()
{
if [ ! -e $1 ]; then
log "Cannot Find $1 to change the IPs. Skipping...";
return;
fi
TEMP="perl -pi -e 's/(^|[\s.=\/:])${OLD_IP}([\s.>:])/\${1}${NEW_IP}\${2}/g' $1"
eval $TEMP;
}
for i in `ls /var/named/temp`; do
{
if [ ! -d /var/named/temp/up10$i.domain.com.db ]; then
continue;
fi
swapfile /var/named/temp/up10$i.domain.com.db
};
done;
I appreciate any help on this.
Thanks,
-Sup.