(Originally asked on Serverfault here )
What do you want to know, exactly?
Is there a simple tool which you can call on a filename which:
- attempts to
flockthe file you want to edit (and lets you know if that failed, and when the lock was acquired by the last person to acquire it), then (if successful)
- copies the file to a working copy
- opens an editor on that working copy, and once the editor exits
- runs an XML validator against the saved working copy to verify that it passes at least a basic sanity check, and then
- if that check is passed, overwrites the original with the working copy, and
- if that check is not passed, gives a helpful error message and asks you if you want to return to the working copy or exit without saving
Ideally, there would be a general-purpose program for this which can validate multipe different file formats depending on arguments (e.g. XML, ini, YAML, JSON, etc.), but honestly all I would need this for is XML. Bonus points if it's in the standard debian repos.
While I could write it myself, that'd be silly if something already existed.
Why do you want this?
I currently work in an environment where not everything is automated. We have hundreds of machines, and we've been running many of them since before the rollout of our automated infrastructure.
It's sad, but it's reality, and it's going to be reality for at least the next year or two.
In the meanwhile, we have some files which we'll need to manually edit (primarily XML), and in so doing two problems tend to arise, namely:
Because two different issue tickets sometimes end up requiring modification to the same file, two people sometimes end up editing the same file and the race condition results in- at best- one persons edits being entirely lost, and
Even if only one person is editing, the server that's using this config files will see they've changed and pick them up once they've been saved. However, being human, sometimes people forget an '=', or a '/', and in between when they save the file and when they realize they screwed up, the server is screwed up.