[lug] Publishing config files

David L. Anselmi anselmi at anselmi.us
Fri Nov 11 17:54:07 MST 2005


Daniel Webb wrote:
[...]
> For the Asterisk config example, I want to do something like this:
> 
> ; !!!REPLACE:12341234:XXXXXXXX!!!
> exten = 12341234,1,SetCIDNum(1112223333)
> exten = 12341234,2,SetCIDName(Someone)
> exten = 12341234,3,Goto(calling_card,s,1)

Rather than a comment that says "12341234 needs replacing", how about a 
comment that says "this is the Perl to run to sanitize this file".  Then 
you write a script that processes the the files and runs the appropriate 
code for each.

Maybe that's overkill for your case--you always have one (or a few) 
strings in a file to replace.  But in the case of a shadow file, etc., 
you might have a field that needs replaced.

But how's this (works at least for the above, leave off the trailing !!!):

#!/usr/bin/perl -lp

if /!!!REPLACE/ {
   (undef, $pat, $repl) = split(/:/);
   $_ = "";
}
s/$pat/$repl/;

You can do various fooling to turn it into one line, depending how picky 
you are.

Dave



More information about the LUG mailing list