#!/usr/bin/env bash # exit if a command fails set -o errexit # display last non-zero exit code in a failed pipeline set -o pipefail # make sure the correct number of arguments are passed; if not, output syntax and exit if [ "$#" -eq 1 ]; then ping -O "$1" 2>&1 | while read -r PONG; do echo "$(date): ${PONG}"; done elif [ "$#" -eq 2 ]; then ping -O "$1" 2>&1 | while read -r PONG; do echo "$(date): ${PONG}" | tee -a "$2".log; done else echo "Usage: pinglog
[logfile name]" exit 1 fi