Solved

script to edit hosts file

Posted on 2013-01-22
8
507 Views
Last Modified: 2013-01-22
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
Comment
Question by:redsox01532
  • 4
  • 3
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 38805295
sed -i.bak '/127.0.0.1/s/#//' hostsfile
0
 

Author Comment

by:redsox01532
ID: 38805302
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
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 38805303
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
 

Author Comment

by:redsox01532
ID: 38805309
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 38805376
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
 

Author Comment

by:redsox01532
ID: 38805412
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
 
LVL 18

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 38805434
You can just ignore that because # is like comment and the dos ignores the characters whatever follows # on the line.
0
 

Author Comment

by:redsox01532
ID: 38805451
great.  Thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Batch File - Display current time and date in FOR command 8 67
Java Loop 6 50
egit plugin on eclipse 8 41
"Black Box" Testing of Control System Software 2 26
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now