[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Updating /etc/hosts automatically / behavior of sed command

Your issue lies in the line: sed -e "s/$REGISTERED_IP/$CURRENT_IP/g" /etc/hosts > /etc/hosts.new
Take a look at the modification I made below, it should help.

if [ $CURRENT_IP != $REGISTERED_IP ] ; then

   echo -n "IP address has changed: creating a new /etc/hosts file"

   sed -i.old "s/$REGISTERED_IP/$CURRENT_IP/g" /etc/hosts

   echo "."


   echo "IP address hasn't changed: no update needed."


Hope this helps.


Reply to: