Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: need to be able to search/replace by ip and hostname recursively in /etc based off ARG input

by arkturuz (Curate)
on Jul 25, 2013 at 09:39 UTC ( #1046307=note: print w/ replies, xml ) Need Help??


in reply to need to be able to search/replace by ip and hostname recursively in /etc based off ARG input

If you need to use system(), then use it. It's done thousands of times per day on a typical machine. If your script is not run every second or so, then it's probably ok. On the other hand, changing potentially a lot of files in /etc might be a bad thing. What if you want to change it all back? Learn to use firewall rules (it could be a really simple solution with those) if you need to redirect traffic or something like that. I would suggest, if you really want to do this, to go simple like:

perl -p -i -e 's/$old_ip/$new_ip/g' /etc/*files_to_change*
Consult perlrun documentation for "-i" switch and backup options when changing a lot of files like this.


Comment on Re: need to be able to search/replace by ip and hostname recursively in /etc based off ARG input
Download Code
Re^2: need to be able to search/replace by ip and hostname recursively in /etc based off ARG input
by globalsec23 (Initiate) on Jul 25, 2013 at 15:58 UTC

    Hi thanks for the reply, let me clarify a few points

    This program is designed to help speed up the deployment of provisioning new virtual machines based off a lamp stack clone with all our post install steps, so this wouldn't ever be undone and firewall rules are not relevant in the scenario

    It would be run once per server during the deployment process

    I was simply trying to not have to rely on system and learn a more best practices way of adjusting files in a search and replace scenario

    also the number of files to adjust is under 20

    hopefully tht clarifies my desires and the purpose better, thanks

      Yes, it's more clear now. I think a simple script I mentioned before would be enough for this. It works out of the box - opens every file you specify, replaces what you need to replace and, most important, is very short code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046307]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-12-29 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls