• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 557
  • Last Modified:

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.
0
redsox01532
Asked:
redsox01532
  • 4
  • 3
1 Solution
 
ozoCommented:
sed -i.bak '/127.0.0.1/s/#//' hostsfile
0
 
redsox01532Author Commented:
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?
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
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
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
redsox01532Author Commented:
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.
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
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
0
 
redsox01532Author Commented:
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?
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
You can just ignore that because # is like comment and the dos ignores the characters whatever follows # on the line.
0
 
redsox01532Author Commented:
great.  Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now