Skip to content

Instantly share code, notes, and snippets.

@paulbdavis
Last active December 14, 2015 22:09

Revisions

  1. paulbdavis renamed this gist Mar 13, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. paulbdavis created this gist Mar 13, 2013.
    13 changes: 13 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #!/usr/bin/env bash

    if [ "$1" = "-r" ]
    then
    rm $HOME/.externalip
    exit 0;
    fi
    cacheFile="$HOME/.externalip"
    if [ ! -f "$cacheFile" ] || [ ! "$(cat $cacheFile)" ]
    then
    wget http://checkip.dyndns.org/ -q -O - | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>' > "$cacheFile"
    fi
    echo $(cat "$cacheFile")