I realized I made a
very minor boo-boo by hard-coding the file names in the echo statements. Went to fix it, but apparently WHT bans edits after 15 mins.
I did test it this time and works like a charm. Enjoy!
Code:
#!/bin/bash
# Greps & optionally replaces IPs in ${HTTPDCONF} and ${BINDCONF}
# 2012-02-14 - bdowne01@wht - Initial Ver
HTTPDCONF="/usr/local/apache/conf/httpd.conf"
BINDCONF="/var/named/domain.tld.db"
GREPIP=${1}
REPLIP=${2}
if [[ -z "${GREPIP}" ]]
then
echo "Usage: ip.sh <grepped IP> (replacement IP)"
echo "Replacement IP is optional. If specified, it is the replacement pattern for <grepped IP>"
exit 1
fi
echo "Testing ${HTTPDCONF} for ${GREPIP}..."
grep -q "${1}" ${HTTPDCONF}
if [[ ${?} -ne 0 ]]
then
echo "Nothing found in ${HTTPDCONF}."
else
echo "${GREPIP} was found in ${HTTPDCONF}"
if [[ -n ${REPLIP} ]]
then
echo "Replacing ${GREPIP} with ${REPLIP} in ${HTTPDCONF}"
sed -ie "s/${1}/${2}/g" ${HTTPDCONF}
fi
fi
echo ""
echo "Testing ${BINDCONF} for ${GREPIP}..."
grep -q "${1}" ${BINDCONF}
if [[ ${?} -ne 0 ]]
then
echo "Nothing found in ${BINDCONF}."
else
echo "${GREPIP} was found in ${BINDCONF}"
if [[ -n ${REPLIP} ]]
then
echo "Replacing ${GREPIP} with ${REPLIP} in ${BINDCONF}"
sed -ie "s/${1}/${2}/g" ${BINDCONF}
fi
fi