script to update /etc/hosts
Please let me first apologise if this is the wrong place to post this, but I am not a regular on this forum so this seemed a good place to me.
I have a machine connected via ADSL with a dynamic ip address. I want to include a little scriplet which will update my dynamic ip address in /etc/hosts. Right now my /etc/host has this entry: 127.0.0.1 localhost.localdomain localhost I want the scriptlet (which I was thinking to include it as part of /etc/ppp/ip-up ) to add a second line containing ipaddress hostname.mydomain hostname. I found this so far, which retrieves my dynamic ip address: exec /sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed - e "s/.*:// which if I execute in shell will give me the ip address. Could someone help me finish this off? Thanks a lot PS I promise that I will study the vi, sed....etc manuals in detail, but for now I just need this script to work..... please..!!! .. |
Quick and dirty hint - use echo
echo "`exec /sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed -e s/.*://` hostname domain" >> /etc/hosts |
but then of course you'll screw up the file if that runs more than once.... either keep a backup copy that you can copy to /etc/hosts and append each time or similar
|
Yeah that's true, it only runs once, for the second time it will screw up the file, thanks acid for pointing it out
|
no problem. any petty detail, no matter how pointless... i'm your man. :)
|
heads up, acid :p . I just thought of a quick solution and it would be to delete /etc/hosts and then create it
Code:
#!/bin/sh |
thanks guys, this did the trick. I still can't get aolserver to see the new ipaddress and hostname, but this is a different matter altogether.
all the best |
ahh but then you're deleting the file and then overwriting it regardless.... remove the rm and you'd never know the difference
|
thanks a lot
All done, aolserver serving what is supposed to serve on the right port, script works a treat.
Thank you once again |
All times are GMT -5. The time now is 10:22 AM. |