0

I am using RHEL 7.0 system. I have this boot.cfg file that has the following fields:

bootstate=0 title=Loading ESXi installer timeout=5 prefix=http://172.32.88.150/esxi65 kernel=tboot.b00

kernelopt=runweasel formatwithmbr

How can I update this boot.cfg file's IP address?

I have earlier used the following script:

#!/bin/bash

sed '/[kernel=tboot.b00]/a [prefix=http://172.32.88.149/esxi65]/' boot.cfg


I was trying to append the updated IP address using sed to the end of the "kernel..." field. but it didn't make any changes.

Secondly, how do I ensure that the changes to the IP address is saved and not temporary?

Thanks in advance

2 Answers2

0

Input file

bootstate=0 title=Loading ESXi installer timeout=5 prefix=http://172.32.88.150/esxi65 kernel=tboot.b00

Command


sed -i  "s;kernel.*;&[prefix=http://172.32.88.149/esxi65];g" boot.cfg

After executing above command boot.cfg will be as below

bootstate=0 title=Loading ESXi installer timeout=5 prefix=http://172.32.88.150/esxi65 kernel=tboot.b00[prefix=http://172.32.88.149/esxi65]
  • There was no effect on the boot.cfg. I am using the owner permissions of rwx but it still does not save the changes. – MightStackier Dec 08 '17 at 10:14
  • Use below command to get it saved permanently sed -i “s;kernel.*;&[prefix=http://172.32.88.149/esxi65];g" boot.cfg – Praveen Kumar BS Dec 08 '17 at 10:39
  • Kumar : hi I received the following error when I tried your suggestion: sed: no input files ./: line 13: boot.cfg: command not found – MightStackier Dec 11 '17 at 03:00
  • @MightStackier i edited the code in answer Kindly check and update – Praveen Kumar BS Dec 11 '17 at 17:12
  • Kumar: No errors and the file was updated permanently. It finally worked! Thank you! – MightStackier Dec 12 '17 at 01:38
  • Kindly Vote for my answer – Praveen Kumar BS Dec 12 '17 at 01:39
  • I realised that the earlier predix address was still there as i thought the 'append' can replace it. Any way to replace the old IP address in the 'prefix' field? to further improve the above script.Can add the new answer in another field? I have referred to this https://unix.stackexchange.com/questions/159367/using-sed-to-find-and-replace solution earlier but received the following error: sed: -e expression #1,char 30: unknown option to 's' – MightStackier Dec 12 '17 at 06:54
0

ALright I found my own answer to the second question credit to http://brunolinux.com/02-The_Terminal/Find_and%20Replace_with_Sed.html

in order to fully replace/update the prefix field instead of appending an earlier field,"escape sign" ( \ ) is needed.The modified code is as follows:

sed -i 's;prefix.*;prefix=http://172.32.88.149/esxi65;g' boot.cfg

Appreciate the earlier help from kumar and the above mentioned website!