Last active
September 4, 2017 04:15
-
-
Save aconz2/509c0f0738c2b5c4d243e10e488c00d5 to your computer and use it in GitHub Desktop.
a simple alternative to something like dyn-dns for remoting into home servers
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
#!/usr/bin/env bash | |
# requires the google-cloud-sdk | |
# to activate key | |
# google-cloud-sdk/bin/gcloud auth activate-service-account --key-file foobar.json | |
# be sure to run the above as root user as well for cron use | |
# to fix timeskew | |
# sudo service ntp stop | |
# sudo ntpd -gq | |
# sudo service ntp start | |
# this needs to be owned by root | |
# sudo chown root update-ip | |
# and be 755 in order to be run by cron | |
# sudo chmod 755 update-ip | |
# move or symlink into /etc/cron.daily/ | |
# sudo ln -s `readlink -f update-ip` /etc/cron.daily/ | |
F=/tmp/current-ip | |
LOCATION="gs://BUCKET/FILENAME" | |
if curl ipinfo.io/ip > "$F"; then | |
if grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' "$F"; then | |
gsutil cp "$F" "$LOCATION" | |
else | |
echo "Was not an ip" | |
fi | |
else | |
echo "curl failed" | |
fi | |
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
[Unit] | |
Description=update ip | |
[Service] | |
ExecStart=/bin/bash /home/pi/update-ip |
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
[Unit] | |
Description=Run update-ip weekly | |
[Timer] | |
OnCalendar=daily | |
Persistent=true | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
systemd files go in
/etc/systemd/user/
then do