-
-
Save Deuteu/5f24151fe48f6ad74e14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#This one mails you the ip if it changes | |
#Deuteu inspired and guided by Allegrem | |
#Env variables | |
path="/home/user/ip_script" | |
old="$path/ip_old.dat" | |
mail="$path/ip_mail.txt" | |
log="$path/ip_log.log" | |
#IP | |
T1=`curl -s icanhazip.com` | |
#curl ipinfo.io/ip #IPv4 | |
#curl ifconfig.me #IPv4 | |
#curl -s icanhazip.com #IPv6 | |
read T2 < $old | |
#Mail variables | |
from="[email protected]" | |
to="[email protected]" | |
head="From: $from | |
To: $to | |
Subject: IP Adress | |
" | |
body="Computer IP is: $T1" | |
echo "$head" > $mail | |
date >> $mail | |
echo "$body" >> $mail | |
if [ "$T1" = "" ]; then | |
echo "[`date`] - [ip_update] - IP couldn't be retrieve - doing nothing" >> $log | |
elif [ "$T1" = "$T2" ]; then | |
echo "[`date`] - [ip_update] - IP is the same: $T1 - doing nothing " >> $log | |
else | |
echo "[`date`] - [ip_update] - IP has changed: $T1 - send mail" >> $log | |
/usr/sbin/sendmail [email protected] < $mail | |
echo "$T1" > $old | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment