Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sed with the EDITOR variable in a script for virsh or sudoers

Tags:

bash

sed

Long story short, I need the command below to work in a bash script.

I need to change the network subnet which a virtual kvm is using. What makes this hard for me is trying to get it to change as a command. Normally you run the command sudo virsh net-edit default and it opens a vi (or whatever) session and you edit and close.

net-edit Option allows the user to edit the XML configuration of a virtual network, using their preferred editor. net-edit launches the command (or script) is defined in the users $EDITOR environment variable, passing it a temporary copy of the XML configuration for the virtual network.

When the user exits the editor, net-edit checks if the temporary file was changed.

So for me, I want to pass this through sed so I can use it in a script. The following example would work from the command line, but it will not work for me in a script. I am not sure what I am doing wrong but I have not figured this out yet. If anyone has an ideas, it would be greatly appreciated.

This works from the command line, but not in a script. Get error messages about the command :

    EDITOR='sed -i "s/192.168.100.1/192.168.11.1/g"' virsh net-edit default

This is a related thread: Changing the dhcp IP range in Virbr0's XML file using virsh in bash script

This is the error message

./test: line 2: export: `net-edit': not a valid identifier

like image 278
Mike Q Avatar asked Mar 21 '26 21:03

Mike Q


1 Answers

I had a problem with the sed command in a couple of ways and at one point I forgot to run it with root authority so in short, the command above WILL work in a script.

like image 90
Mike Q Avatar answered Mar 24 '26 16:03

Mike Q



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!