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:

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 | 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

curl -s | 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

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

No hay comentarios.:

Kill process in one console command line

example:   $ sleep 3600 & [ 1 ] 2225 $ sleep 3600 & [ 2 ] 2226 $ sleep 3600 & [ 3 ] 2227 $ sleep 3600 & ...