hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : script to do this?
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

script to do this?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-14-2012, 11:50 AM
BiggyMike BiggyMike is offline
Aspiring Evangelist
 
Join Date: Jan 2012
Posts: 356

script to do this?


is there a script that allows me to grep and replace IPS in the named/BIND DNS files and the httpd.conf file all at the same time?

Reply With Quote


Sponsored Links
  #2  
Old 02-14-2012, 12:18 PM
bdowne01 bdowne01 is offline
Junior Guru Wannabe
 
Join Date: Oct 2011
Location: Redding, CA
Posts: 60
You might have to write a small shell script to do it... If you can provide some of the paths and file names I could probably whip something up in a few minutes.

__________________
||| Brian Downey
||| Senior Engineer & Text-Fu Blackbelt, The Linux Fix LLC
||| Quality Linux Dedicated Servers | SAS70 Certified Datacenter
||| Linux web hosting | Professional Services | 99.99% Uptime

Reply With Quote
  #3  
Old 02-14-2012, 03:08 PM
BiggyMike BiggyMike is offline
Aspiring Evangelist
 
Join Date: Jan 2012
Posts: 356
well httpd.conf is /usr/local/apache/conf/httpd.conf

named files are kept as /var/named/domain.tld.db

Reply With Quote
Sponsored Links
  #4  
Old 02-14-2012, 08:14 PM
bdowne01 bdowne01 is offline
Junior Guru Wannabe
 
Join Date: Oct 2011
Location: Redding, CA
Posts: 60
Here you go. This is untested! Make sure you try it out on some dummy files first. If it doesn't work, let me know.

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 httpd.conf 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 domain.tld.db 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

__________________
||| Brian Downey
||| Senior Engineer & Text-Fu Blackbelt, The Linux Fix LLC
||| Quality Linux Dedicated Servers | SAS70 Certified Datacenter
||| Linux web hosting | Professional Services | 99.99% Uptime


Last edited by bdowne01; 02-14-2012 at 08:26 PM.
Reply With Quote
  #5  
Old 02-14-2012, 08:33 PM
bdowne01 bdowne01 is offline
Junior Guru Wannabe
 
Join Date: Oct 2011
Location: Redding, CA
Posts: 60
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

__________________
||| Brian Downey
||| Senior Engineer & Text-Fu Blackbelt, The Linux Fix LLC
||| Quality Linux Dedicated Servers | SAS70 Certified Datacenter
||| Linux web hosting | Professional Services | 99.99% Uptime

Reply With Quote
  #6  
Old 02-15-2012, 12:03 AM
BiggyMike BiggyMike is offline
Aspiring Evangelist
 
Join Date: Jan 2012
Posts: 356
Wow thanks a lot!

Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Bash Script] How to set up redirect of script output within script 96mb Programming Discussion 2 07-17-2011 09:10 PM
Clearance - MS script, SMS script, Train script, Game Cheat Scripts & More!! cnv Other Offers & Requests 14 06-08-2006 08:41 PM
iHost 1.01 - Auto Account Creation and Billing Script | iSupport 1.05 Helpdesk Script listenmirndt Other Web Hosting Related Offers 7 04-16-2005 04:00 AM
iHost 1.01 - Auto Account Creation and Billing Script | iSupport 1.05 Helpdesk Script listenmirndt Other Web Hosting Related Offers 4 03-02-2005 06:33 AM
iHost 1.01 - Auto Account Creation and Billing Script | iSupport 1.05 Helpdesk Script listenmirndt Other Web Hosting Related Offers 5 02-14-2005 07:24 PM

Related posts from TheWhir.com
Title Type Date Posted
Pingdom Talks Top Web Hosting Cities and Countries Web Hosting News 2013-03-27 18:49:54
Whistleblower Site Cryptome Hacked, Infects PCs with Drive-By Exploits Web Hosting News 2012-02-14 14:48:24
Control Panel cPanel Launches New Apache Configuration Script Web Hosting News 2011-12-28 19:41:39
Web Host HostingZoom Adds Softaculous Auto-Installer to Hosting Plans Web Hosting News 2011-08-17 17:52:34
Web Host JaguarPC Adds Auto-Installer Softaculous to Hosting Plans Web Hosting News 2011-07-27 18:55:46


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?