-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendipcheck.sh
More file actions
24 lines (19 loc) · 970 Bytes
/
sendipcheck.sh
File metadata and controls
24 lines (19 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# check and send ip address to email
#run this first. may need to edit to match correct grep pattern for your system (i.e. 'iet addr:<IP first 3>', 'eno1', eth1', etc)
MYIP=`ifconfig | grep 'inet addr:' | awk '{print $2}' | cut -d ":" -f2`;
TIME=`date`;
LASTIPFILE='~/.last_ip_addr';
LASTIP=`cat ${LASTIPFILE}`
ipadd=$(cat <<EOF
{"text":"New IP address for $HOSTNAME is $MYIP on $TIME Have a great day!"}
EOF
)
if [[ ${MYIP} != ${LASTIP} ]]
then
curl -k w-X POST -H 'Content-type: application/json' --data "$ipadd" <INSERT SLACK WEBHOOK URL HERE - details:https://api.slack.com/messaging/webhooks>;
echo ${MYIP} > ${LASTIPFILE}
fi
#replace the <> and everything in them with your slack webhook url
#save this script somewhere on your server and add it as a cronjob! It should send a ping to your specified slack channel whenever you IP address changes (such as during power outages)