[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: OT: Sed/Perl script tp comment out specifc line
- From: Cameron Simpson <cs zip com au>
- To: redhat-list redhat com
- Subject: Re: OT: Sed/Perl script tp comment out specifc line
- Date: Sat, 1 Sep 2001 18:10:25 +1000
On Fri, Aug 31, 2001 at 03:27:37PM -0700, Chuck <redhat clinicomp com> wrote:
| I have about 200 remote servers that run a custom application each with
| a tailored config file (ie no two are the same). I need to comment out 2
| lines that are the same in every file for all 200 servers. What is the
| easiest way to do this? I currently use rsh to manage these servers so I
| wanted to create a script, either in perl or sed, that can modify the
| file, distribute this script to each host and execute it there.
Me, I'd use bsed:
http://www.zip.com.au/~cs/scripts/bsed
It's just a wrapper for sed which you invoke like sed:
bsed sed-arguments... filenames
and it edits the files. I find it VERY handy.
Then devise a sed script to do the job for you, eg:
/ptn-matching-the-target-line/s/^/# /
Test it on a few same files.
Then, presuming you've installed bsed on your machines, go:
for h in `cat the-list-of-machines`
do rsh $h '/path/to/bsed "/ptn-matching-the-target-line/s/^/# /" the-file'
done
Note the quoting above. As I'm sure you're aware the arguments you pass to
rsh gets handed to the shell at the far end as a single string, so quoting
happens twice: once in the shell at this end where you're invoking rsh,
and once at the far end. So above I've put the whole line in single quotes
at this end so the double quotes get through to the far end. However,
since they're double quotes, if your ptn-matching-the-target-line has
any shell parameters subst characters in it ($ and `, that is) then they
will need extra protection. This is of course the case for anything you
do with rsh, nothing bsed specific here.
Cheers,
--
Cameron Simpson, DoD#743 cs zip com au http://www.zip.com.au/~cs/
But in our enthusiasm, we could not resist a radical overhaul of the
system, in which all of its major weaknesses have been exposed, analyzed,
and replaced with new weaknesses. - Bruce Leverett
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]