RPi3 Auto Email New Public IP If Changed (Shell)
Step
Use
wgetto download IP-Reporting scriptsudo wget https://raw.github.com/carry0987/Raspberry-Pi-Repo/master/Auto-Report-IP/report-ip.sh
Give the script executing permission
sudo chmod +x report-ip.sh
Enter your gmail address and receiver email address to the script
sudo vim report-ip.sh
Enter your gmail password to
ssmtp.confsudo vim /etc/ssmtp/ssmtp.confNote : If your gmail have set
Two-Step Verification, you should follow the step to get token:- Log-in into Gmail with your account
- Navigate to https://security.google.com/settings/security/apppasswords
- In 'select app' choose 'custom', give it an arbitrary name and press generate
- It will give you 16 chars token
- Use the token as password with your Gmail account and two factor authentication will not be required.

Move
report-ip.shto usr foldersudo mv report-ip.sh /usr/local/bin
Create a systemd service to make the script will auto be run on boot It can auto check the network connection make sure the network is online so that it can send the email
sudo wget https://raw.github.com/carry0987/Raspberry-Pi-Repo/master/Auto-Report-IP/report-ip-sh.service
Move
report-ip-sh.serviceto systemd foldersudo mv report-ip-sh.service /etc/systemd/system
Enable the service
sudo systemctl enable report-ip-sh
Start the service
sudo systemctl start report-ip-sh
Use
systemctlto check the status of the servicesudo systemctl status report-ip-sh
Now edit crontab to make the script run every minutes
sudo vim /etc/crontab
Add the following script on the bottom, then save and exit
* * * * * root /bin/bash /usr/local/bin/report-ip.sh >/dev/null 2>&1
Restart cron service
sudo service cron restart
Finish