Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating the hosts file automatically in SCO 5.0.5

Status
Not open for further replies.

glajos42

Programmer
Dec 20, 2002
8
US
Is there a way to automatically or dynamically update the hosts file in SCO? I am trying to have the information added to it when a certain process is run by a user. If anyone has a script that does this or if there is a way to configure it to dyanmically do it it would be a great help.
 
If you are just adding new entries they can be added to the end of the file simply using echo 1.2.3.4 newhostname >> /etc/hosts. The script doing the update will need to run as root to update the file though.

Changing existing entries would be a little more complicated.

To avoid giving this user root access or having a setuid script, you could have a cron job that tests for the existence of an updates file periodically, such as /var/tmp/new_hosts_entries, and concatenates them to the end of the hosts file if present, e.g.:

[tt]27 * * * * cd /var/tmp && [ -r new_hosts_entries ] && cat new_hosts_entries >> /etc/hosts && mv new_hosts_entries new_hosts_entries.`date +\%Y\%m\%d\%H\%M\%S[/tt]

So the user could create the new entries in that file, they would be added to the /etc/hosts file, and then the new_hosts_entries file copied with a date stamp so you have an audit trail of sorts.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top