Maybe it’s useful for somebody.
Checks ip and sends to your email., if it has changed. Save as ipcheck.sh and put on /home/USER/
To check every hour, execute crontab -e and add this to the end:

0 * * * * sh ipcheck.sh

Here it goes:

#!/bin/sh

#########################
## uncomment and edit as needed
#########################
#mail_to="email@sapo.pt"
#mail_from="email@sapo.pt"
#user="email@sapo.pt"
#pass="password123"
#host_params="--host=smtp.sapo.pt --port=587 --tls=on --tls-starttls=on --auth=on"

#########################
## do not edit lines bellow
#########################
ip_old=""
ip_new=""
if [ -f ip.txt ]; then ip_old="$(cat ip.txt)";  fi
ip_new="$(curl --connect-timeout 10 --max-time 10 --retry 3 --retry-delay 0 -s icanhazip.com)"

if [ "$ip_new" != "" ] && [ "$ip_new" != "$ip_old" ]
then
echo $ip_new > ip.txt
printf "To:$mail_to\nSubject: IP\n\nOld ip = $ip_old\nNew ip = $ip_new" | msmtp --timeout=10 -t --from=$mail_from --user=$user --passwordeval="echo '$pass'" $host_params
fi
  • manned_meatball
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 year ago

    cool, I’ve been using curl -s ifconfig.me after dig +short myip.opendns.com stopped working