-2

I am in the process of selling a network of 60 sites, they all have adsense with the same publisher id (google_ad_client="pub-xxxxxxxxxxxxxxxx") in all the files in the /home/ folder.

How can I do a mass search/replace from ssh to change my id to the buyer id?

1 Answer 1

4

So you want to ssh to each machine and make that change? Should be pretty straightfoward with ssh and expect. Check out this stackoverflow question about that approach. Basically you just need to use expect to automate the ssh logins and then run something like this on every server (all via expect):

find /home/ -type f -maxdepth 1 -print0 | xargs -0 sed -i 's/pub-xxxxxxx/pub-12345/'

that will use sed to edit every file in-place in /home (and no lower in the tree) and replace occurrences of the first string with the latter.

If this is more than a one-time thing you can look into automating this more cleanly, like setting up passwordless ssh logins to eliminate the expect step. However if I understand your question correctly you are really looking for a one-time solution, which is why I say use expect this way.

4
  • Thanks that helped, I actually only need to login on one machine as root, it's a dedicated server.
    – jejasmin
    Jan 10, 2011 at 23:30
  • Oh ha, then that's a lot easier. Just log in and run a sed script! Jan 11, 2011 at 0:17
  • 1
    For me, it says find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments. I'm on centos 6! Thank you!
    – Kleidi
    Jan 26, 2016 at 2:35
  • Ok then just try find -maxdepth 1 /home/ -maxdepth1 -print0 etc Jan 26, 2016 at 6:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .