[mdlug] change ip in config

Dan Pritts danno at umich.edu
Fri Jun 24 10:11:47 EDT 2011


On Fri, Jun 24, 2011 at 09:42:02AM -0400, Tony Bemus wrote:
> I need help with writing a script.  I need to update a config file every
> time the computer boots.  I got the part to have it run at boot, but I
> need help with writing the script.
> 
> I need to get the current eth0 ip address then replace it in a config
> file.  My googleing found this to get the ip:
> 
> 	# ip addr list eth0 |grep "inet " |cut -d' ' -f6|cut -d/ -f1
> 
> and that out put is the correct IP with just the ip address
> "10.112.5.142".  Now I need to have it replace the IP address in in a
> config file line:
> 
> 	sip.server.host=10.112.5.142
> 
> I guess it could replace the line with a new line "sip.server.host=(ip)"
> replacing the (ip).  

NEWIP=`ip addr list eth0 |grep "inet " |cut -d' ' -f6|cut -d/ -f1`
sed "s/sip.server.host.*$/sip.server.host=${NEWIP}" < configfyle > /tmp/configfyle.tmp.$$
mv /tmp/configfyle.tmp.$$ configfyle

this does no error checking and is not appropriate for serious
production use without adding some.

I'd also check whether your sip software can accept the parameter
on the command line or from an environment variable.  It would
probably be more reliable to do it that way.

danno
--
dan pritts
danno at umich.edu
734-929-9770



More information about the mdlug mailing list