Skip to content

Instantly share code, notes, and snippets.

@ChrisCummins
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisCummins/9240862 to your computer and use it in GitHub Desktop.
Save ChrisCummins/9240862 to your computer and use it in GitHub Desktop.
Automatically grab the contents of a web page on a timer and discard the results. Useful for debugging servers or pretending your website's more popular than it is (sure we can justify the extra dyno now that we're seeing a bump in traffic!).
#!/bin/sh
#
# gravepinger - Pings a website on a timer.
#
test -n "$2" || {
echo "Usage: gravepinger <target> <frequency>" >&2
echo "" >&2
echo "Invokes wget on <target> every <frequency> timespan." >&2
echo "Target can be any web page, e.g. \`http://chriscummins.cc'." >&2
echo "Timespan may be any number suffixed with \`s' for seconds," >&2
echo "\`m' for minutes, \`h' for hours or \`d' for days." >&2
exit 1
}
target="$1"
frequency="$2"
# Written by Hugo Duksis. See: https://gist.github.com/duksis/3891185
urlencode() {
echo -n "$1" | perl -MURI::Escape -ne 'print uri_escape($_)'
}
logfile=~/.gravepinger.$(urlencode "$target").log
tmpfile=/tmp/gravepinger
touch "$logfile" # Create logfile
while true; do
echo "$(date) Ping" >> "$logfile"
wget "$target" -O "$tmpfile" >/dev/null 2>&1 \
|| echo "$(date) Ping failed" >> "$logfile" # Download target
rm -f "$tmpfile" # Remove downloaded file
tail -n-99 "$logfile" > "$logfile.tmp" # Rotate logfile
mv "$logfile.tmp" "$logfile"
sleep "$frequency" # Rinse and repeat...
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment