Shell Script to post your external IP address to Ubuntu One.

Because I use ssh a lot between my 2 desktops and my laptop (sometimes even mobile phones) and I also don’t have a static IP address, I needed a way to keep updated with my desktop external IP. there is nothing more easier or convenient than shell scripts in Linux.

the idea was to get my external IP and then have it delivered to me somehow.. all i could think about was to email it to my self somehow, but then i got this idea to use the script to post the IP to a text file which is located on a shared folder on Ubuntu One so every time I run the script it would get my IP address and then post it to a txt file on Ubuntu One folder that gets updated on the cloud across all connected devices and its accessible from the internet using my account. I wanted to share this simple way i thought of and maybe someone out there would find it helpful.

Requirements:-
*note that the requirements could be changed if you modified the script with your commands*
– lynx web browser which is a text based web browser. more info about it Here. It can be easily installed on Ubuntu using the following command:-

sudo apt-get install lynx

– Ubuntu One account and configured on the computer with auto sync of any folder.

That’s it really, next thing is to write or copy the following script in a text file using any text editor such as gedit and save the file with the name you like ending with  .sh

#!/bin/bash
echo $(date) >> Ubuntu One/ip.txt
lynx -dump “http://www.whatismyip.com/” | grep ‘Your IP Address Is:’ >> Ubuntu One/ip.txt 

after you save it make sure to give it permission to run as an executable which is easily done with a right click > properties > permissions > allow executing the file as program.

as you can see in the script.. it visits the site “whatismyip.com” then greps the line which contain “Your IP Address Is:” and then append it to ip.txt in the Ubuntu One folder along with the date and time.
the next thing would be to make the script run at start-up and enjoy knowing your external IP always from anywhere easily.

if you have any suggestions or another way or feature you might think of, please do share it with me 🙂