[SOLVED] Replacing line in xml on remote linux unit over ssh
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
As you can see the only real change that needs to be made is the 9100 value.
When I run this I get the following error:
sed: -e expression #1, char 63: unknown option to `s'
I have tried to escape the 's' and that doesn't seem to work either.
I suppose I can resort to pulling the file, editing it locally and then sending it back. But I know there must be a way to do this by executing a one-liner via ssh. I just can't seem to figure it out. Any help would be greatly appreciated.
Last edited by keif; 02-04-2016 at 02:47 PM.
Reason: added sign off
The problem that you face ... and it is a very, very significant(!) one ... is that you will corrupt the remote XML file and thereby render it inoperable.
A wiser approach would be:
Don't attempt to use sed to update an XML file. Instead, use a "real" programming language that can, using libxml2.so of course, parse the file, change its content, and then rewrite it. (Or, using another tool, safely update it in place.
Use rsync -rsh=ssh to replace the entire file on the remote system.
Use version-control, locally, (e.g. git) to maintain up-to-date copies of present and past "known-good" copies of this file for each remote (on your local system), so that any of them can be restored, anywhere, at will.
The problem that you face ... and it is a very, very significant(!) one ... is that you will corrupt the remote XML file and thereby render it inoperable.
A wiser approach would be:
Don't attempt to use sed to update an XML file. Instead, use a "real" programming language that can, using libxml2.so of course, parse the file, change its content, and then rewrite it. (Or, using another tool, safely update it in place.
Use rsync -rsh=ssh to replace the entire file on the remote system.
Use version-control, locally, (e.g. git) to maintain up-to-date copies of present and past "known-good" copies of this file for each remote (on your local system), so that any of them can be restored, anywhere, at will.
sundialsvcs you are so right. This scenario is a true case to try out Ansible or something like that (I say Ansible because we don't have any Ruby guys on our staff :-)
This is something I have been bringing up in my department. Thank you for your suggestions, they are a great help. Keith
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.