Created
May 25, 2016 09:25
-
-
Save sshnaidm/ddd1d0c0c87d4000215354a1b7cbdec1 to your computer and use it in GitHub Desktop.
update ip with mail
This file contains hidden or 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/sh | |
function get_my_ip (){ | |
myint=$(ip r | grep default | grep -Eo "dev .*" | sed "s/dev //g" | tr -d " ") | |
echo $(ip a | grep "${myint}:" -A7 | grep "inet " | head -1 | awk {'print $2'} | cut -d"/" -f1) | |
} | |
function sendipmail () { | |
newip=$1 | |
nc smtp.redhat.com 25 <<EOF | |
HELO redhat | |
mail from:[email protected] | |
rcpt to:[email protected] | |
data | |
subject:from DELL: My new ip is: $newip | |
Hi, | |
my new ip today $(date) is $newip | |
Thanks, bye | |
. | |
quit | |
EOF | |
} | |
ip=$(get_my_ip) | |
if [[ ! -e /opt/serv/myip ]]; then | |
echo $ip > /opt/serv/myip | |
sendipmail $ip | |
else | |
oldip=$(cat /opt/serv/myip) | |
if [[ "$ip" != "$oldip" ]]; then | |
echo $ip > /opt/serv/myip | |
sendipmail $ip | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment