Skip to content

Instantly share code, notes, and snippets.

@danlopez
Created October 11, 2021 18:37
Show Gist options
  • Save danlopez/321458afbed68624d6098f8fa05d7cf7 to your computer and use it in GitHub Desktop.
Save danlopez/321458afbed68624d6098f8fa05d7cf7 to your computer and use it in GitHub Desktop.
check if IP address matches last know IP, do something if it doesn't.
#!/bin/bash
# Get current IP
ip_address=$(curl icanhazip.com)
echo $ip_address
# Check if IP Address matches last known IP
FILE=/home/pi/scripts/ip.txt
old_ip=$(cat $FILE)
if [[ "$old_ip" != "$ip_address" ]];then
echo "Run a script"
fi
echo $ip_address > $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment