This article is about setting up an automated task, using Lynx and sSMTP.
The goal is to set up a script which will automatically send an email to you with the current external IP address.Lynx is a text browser for the web which you can use through the terminal.
sSMTP is a lightweight mail client (it can not send attachments).
- first install Lynx
sudo apt-get install lynx
You're done. Try this command line and see the result:
lynx -dump http://ipecho.net/plain
(so this command reads the output of the webpage http://ipecho.net/plain and prints it out)
- now install sSMTP
sudo apt-get install ssmtp
edit the ssmtp.conf file
sudo nano /etc/ssmtp/ssmtp.conf
verify that these settings are applied:
- root=postmaster
- mailhub=smtp.gmail.com:587
- hostname=raspberrypi
- AuthUser=YourGmailUserName@gmail.com
- AuthPass=YourGmailPassword
- UseSTARTTLS=YES
To be clear: in this case, the setup is for a gmail account. Change the mailhub if you use another account. Verify your hostname and enter your credentials.
Save and close this file.
Now edit the file revaliases
sudo nano /etc/ssmtp/revaliases
and add a line
pi:youremail@gmail.com:smtp.gmail.com:587
Save and close this file.
Set permissions for ssmtp.conf to 774
sudo chmod 774 /etc/ssmtp/ssmtp.conf
to test, try: lynx -dump http://ipecho.net/plain | mail -s "Your PI IP" me@myemailaddress.com
- instead of typing the complete command, you can create a script. Move to the directory where you want to create it, for example /home/pi and type:
sudo nano sendmemyIP.sh
copy the command line from above into the script and save and close it.
to make a cron job of this, you can copy this script to the hourly crons or daily crons, whichever you prefer:
sudo cp sendmemyIP.sh /etc/cron.hourly/sendmemyIP.sh
No comments:
Post a Comment