-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?

jejasmin
  • 11
  • 1
  • 4

1 Answers1

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.

Phil Hollenback
  • 14,647
  • 4
  • 34
  • 51
  • Thanks that helped, I actually only need to login on one machine as root, it's a dedicated server. – jejasmin Jan 10 '11 at 23:30
  • Oh ha, then that's a lot easier. Just log in and run a sed script! – Phil Hollenback Jan 11 '11 at 00: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 '16 at 02:35
  • Ok then just try `find -maxdepth 1 /home/ -maxdepth1 -print0 etc` – Phil Hollenback Jan 26 '16 at 06:52