Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Poor man's smokeping for OS X
# This script uses the BSD variants of commands and is intended to
# be run on an unmodified installation of OSX.
pmset noidle &
now=$(date +%s)
duration=$((86400*3)) # 3days
end=$((now + duration))
gateway=$(traceroute -f3 -m3 -n 2>&1 | tail -1 | awk '{ print $2 }')
outfile="$(date +%Y-%m-%d)_survey.csv"
while [[ "${now}" < "${end}" ]]; do
now=$(date +%s)
ping=$(ping -t1 -c1 ${gateway} 2>&1)
if [[ "$?" > 0 ]]; then
printf "${now},-1\n" | tee -a "${outfile}"
# 1s ping timeout on failure, so no need to sleep
# Extract (time=14).652 ms from ping output to set $time; lazy but it works
eval $(egrep -o 'time=[0-9]+' <<< "${ping}")
printf "${now},${time}\n" | tee -a "${outfile}"
sleep 1
gzip "${outfile}"
kill %1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment