Shell help with sed replace

Hi,

I have created a www/hiawatha jail template and set the following variable in my config file
Code:
 set MyIPv4     = 10.10.1.17
Once the jail is cloned, I then run a postinstallation script to set create the user, and update various confi files.
In my script, I get the jail ip via
Code:
jailIP=`ifconfig lagg0 | grep inet | cut -w -f3`
which return something like 10.10.1.18 etc
Could anyone please help me understanding how I can replace the ip address my /usr/local/etc/hiawatha.conf with the new IP?

Thank you
 
Try:
Code:
/usr/bin/sed -e "s/^set MyIPv4.*/set MyIPv4     = $jailIP/" -i "" /usr/local/etc/hiawatha.conf
You might also want to consider to use the following command for obtaining the IP address, since it uses only one pipe:
Code:
jailIP=`/sbin/ifconfig lagg0 | /usr/bin/sed -n "/.inet /{s///;s/ .*//;p;}"`
 
Do I need to do something about the space before the work 'set'?
Will that do?
/usr/bin/sed -e "s/\s^set MyIPv4.*/set MyIPv4 = $jailIP/" -i "" /usr/local/etc/hiawatha.conf
 
With a regex(3) the ^ character indicates the beginning of the line, so "\s^" would mean a whitespace character before the beginning of the line, which is impossible. You'll also want to take into account 0 or multiple whitespace characters, "^\s*set...." would be more appropriate.
 
Do I need to do something about the space before the work 'set'?
Will that do?
/usr/bin/sed -e "s/\s^set MyIPv4.*/set MyIPv4 = $jailIP/" -i "" /usr/local/etc/hiawatha.conf
Sorry, I didn't see the space before the keyword set. In case this is guaranteed to be always a single space then do the following:
Code:
/usr/bin/sed -e "s/^ set MyIPv4.*/ set MyIPv4     = $jailIP/" -i "" /usr/local/etc/hiawatha.conf
In case this is an arbitrary indentation, simply remove the ^:
Code:
/usr/bin/sed -e "s/set MyIPv4.*/set MyIPv4     = $jailIP/" -i "" /usr/local/etc/hiawatha.conf
 
Back
Top