delete entry from /etc/hosts file ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete entry from /etc/hosts file ?
# 1  
Old 10-16-2008
delete entry from /etc/hosts file ?

Hi there

I have a requirement where i have to globally remove a hosts file entry from all boxes e.g.

Code:
10.01.10.1           my_server1

normally for 'in-line' editing of files without passing it out to another fle and copying it back etc which is messy, Ive been using the fantastic "perl -pi -e" substitution command. However in this case I want to literally delete the line which im not sure that the perl command can do ?

But ....two things

I want to make sure i delete the line ONLY if both the ip AND the hostname are as defined (so that i know im deleting only this line)

and

the gap between the IP and hostname within the hosts file is variable with any potential number of spaces or tabs in between the two

Does anybody have an idea on how i can achieve this ?

Any help on this would be great
# 2  
Old 10-16-2008
its ok, worked it out
Code:
perl -pi -e "s,^10.10.10.1.*my_server1\n$,," /etc/hosts

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to copy a tar file on a series of remote hosts and untar it on those hosts?

Am trying to copy a tar file onto a series of remote hosts and untar it at the destination. Need to do this without having to do multiple ssh. Actions to perform within a single ssh session via shell script - copy a file - untar at destination (remote host) OS : Linux RHEL6 (3 Replies)
Discussion started by: sankasu
3 Replies

2. How to Post in the The UNIX and Linux Forums

Help me, write a bash script to delete parent entry with all their child entry in LDAP UNIX server

Hi All, Please help me and guide me to write a bash/shell script on Linux box to delete parent entry with all their child entries. example: Parent is : ---------- dn: email=yogesh.kumar@wipro.com, o=wipro, o=in child is: ---------- dn: cn: yogesh kumar, email=yogesh.kumar@wipro.com,... (1 Reply)
Discussion started by: Chand
1 Replies

3. Shell Programming and Scripting

Checking crontab job entry in 3 different hosts

Hi Gurus, I am trying to connect to remote host from current host to check crontab entries. I have started like this ssh -n -l db2psp 205.191.156.17 ". ~/.profile >/dev/null 2>/dev/null; cd log ;ls | wc -l" I got this error ? ssh: connect to host 205.191.156.17 port 22:... (1 Reply)
Discussion started by: rocking77
1 Replies

4. UNIX for Dummies Questions & Answers

Not able to delete this file/directory/entry

Hello UNIX gurus, I noticed this file or whatever in one of our directories, and somehow I am not able to proceed with my work, without deleting this one. .insert--- 1 siebload intrface 0 Feb 22 01:25 Testfile I am confused, as it doesnt appear to be a file, and on doing any... (2 Replies)
Discussion started by: ppathak1234
2 Replies

5. Shell Programming and Scripting

Need to delete duplicate lease entry

Hi *, I need to delete duplicate lease entries in file according to MAC/IP. I'm having tempfile which contains many lease info and need to have one entry for each IP(not more than that), if it contains more than one entry for same set, need to be deleted that entry... EX: lease... (4 Replies)
Discussion started by: SMNK
4 Replies

6. IP Networking

Hosts file ignored, no DNS entry but still routes!!

Hi all, I have an entry in my hosts file on a server called tractor as follows: 10.67.34.128 digger-m2m digger I have a DNS server configured but it doesn't seem to know about digger. When I do an nslookup on tractor for digger i get the following: new_dns1.oam.uk can't find digger: Non... (0 Replies)
Discussion started by: Donkey25
0 Replies

7. UNIX for Dummies Questions & Answers

Compare these two lines and delete the old entry

I have a unique situation here which looks easier at first but I am not able to solve it. # SSort UNIX 10/14/2005 10/13/2010 "tox" "9000/800" 16 * * * V849-6-1 # SSort UNIX 11/31/1996 11/02/2010 "tox" "9000/800" 16 * * * W237-S-2 I have a text file with two or multiple values like this and... (1 Reply)
Discussion started by: pareshan
1 Replies

8. Red Hat

entry in /etc/hosts

Hello all, I´m on Red Hat Enterprise Server 4.5 I´m wondering if it is possible to disable the need to add every IP machine entry in the file /etc/hosts to allow it to connect to Red hat? I´m getting "where are you?" message. This is solved adding the machine ip where I´m working. Thanks in... (1 Reply)
Discussion started by: mig28mx
1 Replies

9. UNIX for Dummies Questions & Answers

Hosts.deny entry

Hello I want to block individuals who attempt to use ssh to loggon to one of my machines from a certain IP address. I added the following entry in hosts.deny. Will the entry do what I want to do? ssh: 202.111.128.225 (3 Replies)
Discussion started by: mojoman
3 Replies

10. Shell Programming and Scripting

shell script to edit file and delete entry

Can anyone provide me a shell script to edit a xml file and delete one entry. To do manually i can edit(vi editor) the file and 'dd' will delete the file.But I wiluld to know if I can do with a script. Thanks in advance Tannu (6 Replies)
Discussion started by: tannu
6 Replies
Login or Register to Ask a Question