Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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

Replies are listed 'Best First'.
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?
[GotToBTru]: 99% of all deaths take place within 24 hours of ingesting di-hydrogen monoxide
[GotToBTru]: time for some C8H10N4O2 for me
[ambrus]: GotToBTru: wait, you tell only the atom totals of what you want? Is that like ordering food in a restaurant by telling only the nutrient amounts you need, or

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2016-12-06 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (104 votes). Check out past polls.