#! /bin/bash cam_ip="$1" wifi_up_logfile="$2" wifi_up='' # Initialize if ping -c3 "$cam_ip" | grep ' 0%' > /dev/null; then wifi_up="yes" echo "$(date +%I:%M:%S) Started logging -- Wifi Up" >> $wifi_up_logfile else wifi_up="no" echo "$(date +%I:%M:%S) Started logging -- Wifi Down" >> $wifi_up_logfile fi # Main loop while true; do if ping -c3 "$cam_ip" | grep ' 0%' > /dev/null; then if [ "$wifi_up" == "no" ]; then echo "$(date +%I:%M:%S) Wifi Up" >> $wifi_up_logfile wifi_up="yes" fi else if [ "$wifi_up" == "yes" ]; then echo "$(date +%I:%M:%S) Wifi Down" >> $wifi_up_logfile wifi_up="no" fi fi sleep 2 done