Skip to content

Instantly share code, notes, and snippets.

@maatthc
Last active May 14, 2019 04:09
Show Gist options
  • Save maatthc/ec4505a0ef10b9fb5e6fba9c74803d63 to your computer and use it in GitHub Desktop.
Save maatthc/ec4505a0ef10b9fb5e6fba9c74803d63 to your computer and use it in GitHub Desktop.
Shell script to post to Slack every time the Raspberry Pi changes its IP Address via DHCP. Should be in the folder /lib/dhcpcd/dhcpcd-hooks/
#!/bin/bash
if [ "$interface" = wlan0 ]; then
if [ "$if_up" = true ]; then
IP=`ip add show wlan0|grep global |awk '{print $2}'`
PREVIOUS_IP=`cat /tmp/notify_output`
if [ "$PREVIOUS_IP" != "$IP" ]; then
echo 'Notifying ip: '$IP' to Slack Channel..'
echo $IP > /tmp/notify_output
curl -X POST -H 'Content-type: application/json' --data '{"text":"RaspBerry TV IP is now: '${IP}'","icon_emoji":":tv:", "username":"RaspBerry"}' https://hooks.slack.com/services/XXXX
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment