Link to home
Start Free TrialLog in
Avatar of redsox01532
redsox01532

asked on

script to edit hosts file

Is is possible to edit the hosts file with a script that the user can run from their machine.  One of our groups needs to remove the # symbol from one line in the hosts file.  The line is:

#    127.0.0.1         localhost

I want to get a script that the user can run that will remove the # symbol from that line.

Any help is much appreciated.
Avatar of ozo
ozo
Flag of United States of America image

sed -i.bak '/127.0.0.1/s/#//' hostsfile
Avatar of redsox01532
redsox01532

ASKER

how would I have the users run this from their pc's?  do I save it as a .bat file or simply run it from the command prompt?
make a new file with no # in it
Then copy that file remotely to all the machines in the given locations replacing the old file or rename the file first then copy
I thought of doing this but a some of the users are field users.  I was hoping to have them run a script from their machine that would do this for them.  Not sure if that is possible.   They need this b/c they are installing an application that needs the # removed from that line in order to work.
Copy the following line into .bat file then ask them to open it which will do the trick



echo "127.0.0.1 localhost" >> C:\Windows\System32\drivers\etc\hosts
thanks.  that added the entry but it didnt remove the #   127.0.0.1 local host entry.  do i need to add something to the bat to do that as well?
ASKER CERTIFIED SOLUTION
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
great.  Thank you.