_______________________________________________________________________ How to Automatically Upload Your RPi's IP Addresses To Your Website _______________________________________________________________________ # by WA8KIM / kim@kim125.com / EchoLink: WA8KIM-R / WiRES-X: Rm#21149 / Last updated 08/24/2015. # http://www.wa8kim.com/rpi.html # Best viewed in Notepad with Word Wrap OFF/UNCHECKED and in full screen Download the latest version of this file at: http://www.wa8kim.com/files/(RPi)%20Upload%20IP%20Addresses%20To%20Website.txt Finding the IP address on a headless RPi with dynamic IP can be tricky. This will create a text file containing all your IP info (LAN, Wifi, Public) and upload it to an FTP server (or website). This is useful, for instance, for mobile use of your SVXLink. Simply view your website on your laptop/PC to find your RPi's address and login. # Create a script that will create a text file with your RPi's IP addresses sudo nano /etc/uploadip.sh ---------------------------------------------------------------------------------------------------------------------- #!/bin/bash echo Creating and uploading IP addresses to website . . . echo "RPi name.......: `hostname` LAN IP Address.: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` Wifi IP Address: `/sbin/ifconfig wlan0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` WAN IP Address.: `wget -q -O - http://icanhazip.com/ | tail` Last Updated...: `date +"%A, %e %B %Y, %r"`" > /home/pi/`hostname`.txt sudo curl -T /home/pi/`hostname`.txt ftp://ftp.yoursite.com/folder/ip/ --user username:password ---------------------------------------------------------------------------------------------------------------------- # Make it executable sudo chmod +x /etc/uploadip.sh # Make it executable at startup via cron. The script wouldn't run via the /etc/rc.local file for some reason crontab -e # FOR --== LAN CONNECTIONS ONLY ==--, add the following text at the end of the crontab config: # The @reboot will run uploadip.sh upon any reboot # The */10 * * * * will run uploadip.sh every 10 minutes ---------------------------------------------------------------------------------------------------------------------- @reboot /etc/uploadip.sh */10 * * * * /etc/uploadip.sh ---------------------------------------------------------------------------------------------------------------------- # FOR --== WIFI AND/OR LAN CONNECTIONS ==--, add the following text at the end of the crontab config: # The 'sleep 120' command gives 120 seconds for a Wifi connection to complete prior to running the script ---------------------------------------------------------------------------------------------------------------------- @reboot sleep 120 && /etc/uploadip.sh ---------------------------------------------------------------------------------------------------------------------- sudo reboot Notes on crontab -e: ------------------------------------------------------ */10 * * * * username /home/pi/command.sh field allowed values ----- -------------- minute 0-59 (10 in my example) hour 0-23 (The second * astericks) day of month 1-31 (The third * astericks) month 1-12 (or names) day of week 0-7 (0 or 7 is Sun, or use names) username username (Optional) command Command/file you want to run ------------------------------------------------------ -------------------- REVISION HISTORY -------------------- 2015-08-24 Updated Download Link 2015-03-10 File Created