Application to Bulk update XML configs

FreePBX bulk utils are really nice - its as simple as export, modify, upload.

But its painful whenever I need to make a change to all the Cisco Phone XML configs. If I wanted to changed the backlight to be Always On, For example, I would find the value I want to change then copy it. Then I would have to open each config seperately, find the line of code and paste over it carefully not to leave any syntax misconfig. Sometimes I have to do this for 30 phones. And then when Im done, I think of another value I want to tweak so i go back and do it all over again.

Is there a program anyone uses for this. It could be as simple as a search and replace tool that works ona group of files or something like that. If not maybe I will try to write my own tool for this and share it here, but Im sure others have a solution

Thanks

That would be easy for sed,

man sed

simply:-

sed -i ‘s/old string/new string/g’ /tftpboot/MACPRREFIX*.match

Sed is pretty awesome. I will read more about it. I will have to do some testing to see how it handles the special characters like “<” “>”

It can handle anything that you throw at it just “escape” characters as needed(as in reserved characters). brush up on your bash usage of single-quotes double-quotes and regexes, everything is then essentially a one-liner

I like using tilde (~) to separate the sed strings so I don’t have to escape slashes. s~original~replace~g has worked out well for me :smile:

It gets more fun

You could consider using php, python, perl, some other language you like…

No escaping needed.

Take a snippet like one of the answers and keep it in your toolbox, adjust as needed in the future. You change a few plain text variables rather than reinventing the wheel writing a new sed expression for every new change.

As James suggests, there is always one or more very complicated ways to skin a cat, choose your poison, I challenge that none could possibly be as simple and understandable as the “one-liner” I originally suggested :slight_smile:

Peta and the aspca has asked that we refrain from skinning cats.

1 Like

hehe James, Indeed,

be wary of the Enron method :wink: