Get my public IP

Usage

This script runs on my home server via chrontab. It gets the public IP and sends it to a secret github gist. It uses the Arch Linux gist package to update the gist.

The same could be achieved on any OS using git commmit and git push.

Code

#!/usr/bin/env bash
#### VARIABLES ####
my_wan_ip="$(curl -s https://checkip.amazonaws.com)"
today_expanded="$(date +%Y.%m.%d_%T)"
gist_id="1234567890abcdef"
wan_ip_file_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)
wan_ip_file="$wan_ip_file_dir/pub_ip.txt"
###################
printf %s\\n "$today_expanded" > "$wan_ip_file" && \
printf %s\\n "$my_wan_ip" >> "$wan_ip_file" && \
gist -u "$gist_id" "$wan_ip_file"