#!/bin/bash # ########################################################################################### # EHU ( /etc/hosts updater ) v0.2 # # code (C) 1999 by rofus # # rofus@mindless.com # # WHAT IS: # # This simple ip-{up-down} script update at every connection (when the ppp daemon starts # # and when is closed) your etc/hosts file with your actual REAL ip and hostname (useful in# # some cases). # # USAGE: # # FIRST of all, you must create a copy of your original /etc/hosts in /etc/hosts.backdark # # This program will read from your original etc/hosts.backdark (IT NEVER WILL BE MODIFIED)# # and add to the new /etc/hosts any lines not commented that you added previously (ie IP # # and hostnames of the machines on your LAN etc.. ). # # Put this file (ip-up) and the ip-down in your etc/ppp/ directory, and make sure # # they have permission x for the user(s) that starts the pppd. # # For any problem/suggestion please email me. # # # # NOTE NOTE NOTE: if you want add new voices at /etc/hosts, YOU MUST ADD them to the # # **/etc/hosts.backdark** file, because the scripts recreate everytime # # a NEW and UPDATED /etc/hosts; so if you add new voices to the # # /etc/hosts.backdark the next time the scripts create a new and # # updated file /etc/hosts also with your new updates. # # # # # # Thanks to Stevenson! and all on IRCnet #linux-it # # # ########################################################################################### ehu () { echo 127.0.0.1 localhost > /etc/hosts ehu1=$(hostname -i) ehu2=$(hostname) ehu3=$(hostname -d) echo $ehu1 $ehu2.$ehu3 >> /etc/hosts egrep -E -v ^#\|^127.0.0.1 /etc/hosts.backdark >> /etc/hosts hostname $ehu2.$ehu3 } if [ -e "/etc/hosts.backdark" ] then ehu else # If the script can't find /etc/hosts.backdark it simply # copy the /etc/hosts and create the file. cp /etc/hosts /etc/hosts.backdark ehu fi