Scripting it automatically.
Have something run from the user's .profile that finds out the
address and updates /etc/hosts (or DNS).
The problem here is that you need root access to update
/etc/hosts. There are three ways to solve that:
- You might use sudo: see http://aplawrence.com/Basics/sudo.html
or (OSR5) "asroot"
or (Unixware) "tfadmin and adminuser"
- Make a setuid binary that runs the script.
- Use a named pipe: the unprivileged client writes to the pipe, a
root owned process reads from it.
Some sample scripts for that are shown below.
# remotelpsetup, run at boot (run in background!)
/etc/fuser -k /dev/remoteprinters
/bin/rm -f /dev/remoteprinters
/etc/mknod /dev/remoteprinters p
exec < /dev/remoteprinters
# pickprinter, called from user's .profile
set `/bin/who -mxu`
MYALREADY=`grep $MYADD /etc/hosts| sed 's/ .*//'`
if [ "$MYALREADY" ]
test -z "$MYADD" && exit 0
case $MYTTY in
*) exit 0;
case $MYADD in
-) exit 0;;
192.168.*) exit 0;;
localhost) exit 0;;
*) : ;;
echo "Please select the printer you wish to use
case $choice in
[qQ]) exit 0;;
if test -z "$PRINTER"
echo "CookieM $PRINTER $MYADD" > /dev/remoteprinters
echo "Printer $PRINTER set for $MYADD"
read key printer address
case $key in
CookieM) : ;;
*) exit 0;;
/bin/grep -v $address /etc/hosts > /tmp/hosts.$$
/bin/grep -v $printer //tmp/hosts.$$ > /tmp/hosts2.$$
echo "$address\t$printer" >> /tmp/hosts2.$$
cp /tmp/hosts2.$$ /etc/hosts
If this page was useful to you, please help others find it:
More Articles by Tony Lawrence
- Find me on Google+
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site:
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Publishing your articles here
Jump to Comments
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.