Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- NEWHOST=`nslookup nuwira.dyndns.org | grep Address | sed '$!d' | sed 's/Address: //'` # getting new IP address
- if [[ $NEWHOST != "" ]]; then # check if there's IP address
- sed 's/^(.*)apihostname$//' /etc/hosts > /tmp/hosts # delete old entry
- sed '$d' /tmp/hosts > /tmp/hosts2 # delete new line, copy to temporary file /tmp/hosts
- echo "$NEWHOST apihostname" >> /tmp/hosts2 # write it to temporary file /tmp/hosts2
- cp /tmp/hosts2 /etc/hosts # done, copy back to /etc/hosts
- rm /tmp/hosts # deleting temporary files
- rm /tmp/hosts2
- echo "IP address: $NEWHOST" # show the new IP address
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement