Networking Forums

Networking Forums > Computer Networking > Linux Networking > Automatic updating of /etc/hosts file?

Reply
Thread Tools Display Modes

Automatic updating of /etc/hosts file?

 
 
Rejected
Guest
Posts: n/a

 
      11-06-2004, 03:26 AM
Here is my dilemia: I have an RS6000 that has IP printers defined to
dynamic DNS addresses. The spooler won't do DNS lookups, so I have to
set the /etc/hosts file to have the DNS entries. To the user login
script I added

export CLIENTIP=`who am i | sed -e 's/^.*(//' -e 's/)//'`

This will set the unix environment variable of CLIENTIP each time a
user logs in. I then want to take this script (dyndns.sh) to update
the /etc/hosts file

#! /bin/ksh
IP=$CLIENTIP
ME=`whoami`rps

if [ "$IP" ]; then
sed '/^--$ME--/,/^--$ME--/'d /etc/hosts > /etc/hosts
echo "--$ME--\n$IP $ME.homelinux.com\n--$ME--" >>/etc/hosts
fi

This would get tricky if multiple users login at the same time, so I
prefer not to create a new file, "> /etc/hosts" (like I'm currently
testing), but edit the existing file on the file.

I'm open to any and all solutions. Please help. Thanks.

Rejected at Hotmail dot com
 
Reply With Quote
 
 
 
 
Rejected
Guest
Posts: n/a

 
      11-06-2004, 03:05 PM
I got my script to work using this syntax:

#! /bin/ksh
IP=`who am i | sed -e 's/^.*(//' -e 's/)//'`
ME=`whoami`rps
if [ "$IP" ]; then
vi -c "/$ME.homelinux.com/d" -c "wq" /etc/hosts 1>/tmp/waste 2>&1
echo "$IP $ME.homelinux.com" >>/etc/hosts
fi

BUT I still have the issue of multiple users editing the /etc/hosts
file. Is there some way to enforce a lock, or a way to include a
lists of hosts from /etc/hosts? Something like #include
/etc/dynamichosts ?

Again any help is appreciated.


(E-Mail Removed) (Rejected) wrote in message news:<(E-Mail Removed). com>...
> Here is my dilemia: I have an RS6000 that has IP printers defined to
> dynamic DNS addresses. The spooler won't do DNS lookups, so I have to
> set the /etc/hosts file to have the DNS entries. To the user login
> script I added
>
> export CLIENTIP=`who am i | sed -e 's/^.*(//' -e 's/)//'`
>
> This will set the unix environment variable of CLIENTIP each time a
> user logs in. I then want to take this script (dyndns.sh) to update
> the /etc/hosts file
>
> #! /bin/ksh
> IP=$CLIENTIP
> ME=`whoami`rps
>
> if [ "$IP" ]; then
> sed '/^--$ME--/,/^--$ME--/'d /etc/hosts > /etc/hosts
> echo "--$ME--\n$IP $ME.homelinux.com\n--$ME--" >>/etc/hosts
> fi
>
> This would get tricky if multiple users login at the same time, so I
> prefer not to create a new file, "> /etc/hosts" (like I'm currently
> testing), but edit the existing file on the file.
>
> I'm open to any and all solutions. Please help. Thanks.
>
> Rejected at Hotmail dot com

 
Reply With Quote
 
Bill Unruh
Guest
Posts: n/a

 
      11-06-2004, 05:25 PM
(E-Mail Removed) (Rejected) writes:

]I got my script to work using this syntax:

]#! /bin/ksh
]IP=`who am i | sed -e 's/^.*(//' -e 's/)//'`
]ME=`whoami`rps
]if [ "$IP" ]; then
] vi -c "/$ME.homelinux.com/d" -c "wq" /etc/hosts 1>/tmp/waste 2>&1
] echo "$IP $ME.homelinux.com" >>/etc/hosts
]fi

]BUT I still have the issue of multiple users editing the /etc/hosts
]file. Is there some way to enforce a lock, or a way to include a
]lists of hosts from /etc/hosts? Something like #include
]/etc/dynamichosts ?

]Again any help is appreciated.


](E-Mail Removed) (Rejected) wrote in message news:<(E-Mail Removed). com>...
]> Here is my dilemia: I have an RS6000 that has IP printers defined to
]> dynamic DNS addresses. The spooler won't do DNS lookups, so I have to
]> set the /etc/hosts file to have the DNS entries. To the user login
]> script I added
]>
]> export CLIENTIP=`who am i | sed -e 's/^.*(//' -e 's/)//'`
]>
]> This will set the unix environment variable of CLIENTIP each time a
]> user logs in. I then want to take this script (dyndns.sh) to update
]> the /etc/hosts file
]>
]> #! /bin/ksh
]> IP=$CLIENTIP
]> ME=`whoami`rps
]>
]> if [ "$IP" ]; then
]> sed '/^--$ME--/,/^--$ME--/'d /etc/hosts > /etc/hosts
]> echo "--$ME--\n$IP $ME.homelinux.com\n--$ME--" >>/etc/hosts
]> fi
]>
]> This would get tricky if multiple users login at the same time, so I
]> prefer not to create a new file, "> /etc/hosts" (like I'm currently
]> testing), but edit the existing file on the file.

Sure. Put in a lock yourself. YOu control that script. Have the script
create and read the lock.

]> I'm open to any and all solutions. Please help. Thanks.
 
Reply With Quote
 
Floyd L. Davidson
Guest
Posts: n/a

 
      11-06-2004, 05:54 PM
(E-Mail Removed) (Rejected) wrote:
>I got my script to work using this syntax:
>
>#! /bin/ksh
>IP=`who am i | sed -e 's/^.*(//' -e 's/)//'`
>ME=`whoami`rps
>if [ "$IP" ]; then
> vi -c "/$ME.homelinux.com/d" -c "wq" /etc/hosts 1>/tmp/waste 2>&1
> echo "$IP $ME.homelinux.com" >>/etc/hosts
>fi
>
>BUT I still have the issue of multiple users editing the /etc/hosts
>file. Is there some way to enforce a lock, or a way to include a
>lists of hosts from /etc/hosts? Something like #include
>/etc/dynamichosts ?
>
>Again any help is appreciated.
>
>(E-Mail Removed) (Rejected) wrote in message news:<(E-Mail Removed). com>...
>> Here is my dilemia: I have an RS6000 that has IP printers defined to
>> dynamic DNS addresses. The spooler won't do DNS lookups, so I have to
>> set the /etc/hosts file to have the DNS entries. To the user login
>> script I added


Why do you have printers with dynamic addresses????

--
FloydL. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) (E-Mail Removed)
 
Reply With Quote
 
chris-usenet@roaima.co.uk
Guest
Posts: n/a

 
      11-06-2004, 08:22 PM
Rejected <(E-Mail Removed)> wrote:
> Here is my dilemia: I have an RS6000 that has IP printers defined to
> dynamic DNS addresses.


An IBM RS6000 running AIX?

> The spooler won't do DNS lookups [...]


Why not? Might it be easier to get this working instead?
Chris
 
Reply With Quote
 
Rejected
Guest
Posts: n/a

 
      11-08-2004, 05:09 PM
> Sure. Put in a lock yourself. YOu control that script. Have the script
> create and read the lock.


I'm not sure on how to implement that?


(E-Mail Removed) (Bill Unruh) wrote in message news:<cmj4vg$15g$(E-Mail Removed)>...
> (E-Mail Removed) (Rejected) writes:
>
> ]I got my script to work using this syntax:
>
> ]#! /bin/ksh
> ]IP=`who am i | sed -e 's/^.*(//' -e 's/)//'`
> ]ME=`whoami`rps
> ]if [ "$IP" ]; then
> ] vi -c "/$ME.homelinux.com/d" -c "wq" /etc/hosts 1>/tmp/waste 2>&1
> ] echo "$IP $ME.homelinux.com" >>/etc/hosts
> ]fi
>
> ]BUT I still have the issue of multiple users editing the /etc/hosts
> ]file. Is there some way to enforce a lock, or a way to include a
> ]lists of hosts from /etc/hosts? Something like #include
> ]/etc/dynamichosts ?
>
> ]Again any help is appreciated.
>
>
> ](E-Mail Removed) (Rejected) wrote in message news:<(E-Mail Removed). com>...
> ]> Here is my dilemia: I have an RS6000 that has IP printers defined to
> ]> dynamic DNS addresses. The spooler won't do DNS lookups, so I have to
> ]> set the /etc/hosts file to have the DNS entries. To the user login
> ]> script I added
> ]>
> ]> export CLIENTIP=`who am i | sed -e 's/^.*(//' -e 's/)//'`
> ]>
> ]> This will set the unix environment variable of CLIENTIP each time a
> ]> user logs in. I then want to take this script (dyndns.sh) to update
> ]> the /etc/hosts file
> ]>
> ]> #! /bin/ksh
> ]> IP=$CLIENTIP
> ]> ME=`whoami`rps
> ]>
> ]> if [ "$IP" ]; then
> ]> sed '/^--$ME--/,/^--$ME--/'d /etc/hosts > /etc/hosts
> ]> echo "--$ME--\n$IP $ME.homelinux.com\n--$ME--" >>/etc/hosts
> ]> fi
> ]>
> ]> This would get tricky if multiple users login at the same time, so I
> ]> prefer not to create a new file, "> /etc/hosts" (like I'm currently
> ]> testing), but edit the existing file on the file.
>
> Sure. Put in a lock yourself. YOu control that script. Have the script
> create and read the lock.
>
> ]> I'm open to any and all solutions. Please help. Thanks.

 
Reply With Quote
 
Rejected
Guest
Posts: n/a

 
      11-08-2004, 05:11 PM
> Why do you have printers with dynamic addresses????

Because we have several sales reps that are home office workers who
have DSL, Cable, etc. Their IP addresses change as per their internet
provider.

(E-Mail Removed) (Floyd L. Davidson) wrote in message news:<(E-Mail Removed)>...
> (E-Mail Removed) (Rejected) wrote:
> >I got my script to work using this syntax:
> >
> >#! /bin/ksh
> >IP=`who am i | sed -e 's/^.*(//' -e 's/)//'`
> >ME=`whoami`rps
> >if [ "$IP" ]; then
> > vi -c "/$ME.homelinux.com/d" -c "wq" /etc/hosts 1>/tmp/waste 2>&1
> > echo "$IP $ME.homelinux.com" >>/etc/hosts
> >fi
> >
> >BUT I still have the issue of multiple users editing the /etc/hosts
> >file. Is there some way to enforce a lock, or a way to include a
> >lists of hosts from /etc/hosts? Something like #include
> >/etc/dynamichosts ?
> >
> >Again any help is appreciated.
> >
> >(E-Mail Removed) (Rejected) wrote in message news:<(E-Mail Removed). com>...
> >> Here is my dilemia: I have an RS6000 that has IP printers defined to
> >> dynamic DNS addresses. The spooler won't do DNS lookups, so I have to
> >> set the /etc/hosts file to have the DNS entries. To the user login
> >> script I added

>
> Why do you have printers with dynamic addresses????

 
Reply With Quote
 
Rejected
Guest
Posts: n/a

 
      11-08-2004, 05:13 PM
chris-(E-Mail Removed) wrote in message news:<jurv52-(E-Mail Removed)>...
> Rejected <(E-Mail Removed)> wrote:
> > Here is my dilemia: I have an RS6000 that has IP printers defined to
> > dynamic DNS addresses.

>
> An IBM RS6000 running AIX?


Yes, I'm sorry I should have said that.


>
> > The spooler won't do DNS lookups [...]

>
> Why not? Might it be easier to get this working instead?

Can you point me in a direction on how to get that to work? I don't
know what I would need to do. The machine does DNS lookups just fine,
just the spooler doesn't seem to.

> Chris

 
Reply With Quote
 
chris-usenet@roaima.co.uk
Guest
Posts: n/a

 
      11-08-2004, 08:36 PM
Rejected <(E-Mail Removed)> wrote:
> Can you point me in a direction on how to get that to work? I don't
> know what I would need to do. The machine does DNS lookups just fine,
> just the spooler doesn't seem to.


When you say "the machine", do you mean general utilities like ping,
telnet, etc., or do you mean that specific DNS tools such as dig and
nslookup work when you use them?

If you find that only dig/nslookup works, and nothing else uses DNS, you
need to check the AIX equivalent of /etc/nsswitch.conf (nameserver switch
file) to ensure that hosts *and* dns is listed against name lookups. You
also need to ensure that the /etc/resolv.conf file is correctly set up.

Someone more familiar with AIX should be able to clarify/correct what
I've written. You may also want to ask in one of the AIX newsgroups.

Chris
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hosts file McHenry Linux Networking 2 06-08-2006 08:03 PM
hosts file Mike Windows Networking 6 01-08-2005 11:17 PM
Hosts file in win 98 SE LBJ Windows Networking 1 12-10-2003 03:19 AM
hosts file frank neuner Windows Networking 1 10-08-2003 07:31 PM
Hosts file in Win 98 John McLean Windows Networking 2 09-08-2003 12:10 PM



1 2 3 4 5 6 7 8 9 10 11