Calling all bash gurus, please give me a shove in the right direction. The following does what I need for only 1 host unreliably and logs too many lines. How do I make it more elegant and functional? Ideally, I would like it to ping with several packets and log ONLY CHANGES. Also, ping SEVERAL hosts. Only log one line when a host is not reachable/unreachable for several packets in a row.
#!/bin/bash
while [ 1 ]; do
ping -c 1 -w 2 $1
if [[ $? == 0 ]]; then
spd-say "up"
notify-send "up"
echo "up $1 $(date +%Y%m%d-%H%M)" >> /tmp/ping.log
else
echo "down $1 $(date +%Y%m%d-%H%M)" >> /tmp/ping.log
fi
sleep 2m
done;