domingo, mayo 31, 2015

Get my public IP and send it via email periodically

in order to get the Public IP assigned from your Internet provider to your router, you can use the free service offer by dyndns:

http://checkip.dyndns.org

but what if you want to get the ip from console and save this into a text file?, this is usefull if later you wants to send this file to some email. If your need is this, so, just follow the next steps tested in Linux Mint.

first try the command via console and look you get the right answer:

$ curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'  > mi_ip

this will copy the Public IP to mi_ip file, just check your file and see the result:

$ nano mi_ip

you can add the command to crontab in order to periodically send you an email with the ip result. For this create a shell script:

$ nano mi_ip.sh

#!/bin/bash
curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//' $
cat ~/mi_ip.txt | mail -s "My IP address is:" put_your_email_here

save and exit nano. Now configure your crontab jobs:

$ crontab -e

put this at the bottom of the file:

#Send mi public ip to my email
@daily put_here_the_path_to_your_shell_script_mi_ip.sh

save and exit. With the option @daily the scritp would be executed each day at midnight. That's all!


No hay comentarios.: