Verified Commit f169f8c0 authored by Fabio Bonfiglio's avatar Fabio Bonfiglio 💾
Browse files

First test

parent 131eb504
#!/bin/bash
# A script to continuously monitor and log internet connectivity in a csv file
# A script to continuously monitor and log internet connectivity failures in a csv file
#
# Author: Fabio Bonfiglio <fabio.bonfiglio@protonmail.ch>
#
......@@ -19,3 +19,45 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
################################################################################
# TODO : try to implement with `ping -c 1 google.com | sed -rn "2s/^.+time=([\d\.]+)/\1/pm"` to obtain response time.
RUNME=1
DISP=1
DESTINATION="checknet.csv"
trap "RUNME=0" INT
echo -e "\nchecknet v0.1.0 - by Fabio Bonfiglio"
while getopts hqf: option; do
case "${option}" in
h)
echo -e "\nUsage: $0 [-h][-d][-f <file name>]"
echo -e "\nOptions:\n\n\t-h\tDisplay this help message."
echo -e "\t-q\tQuiet. Don't show live log feed."
echo -e "\t-f fileName.csv\tIndicate a file path and name where to save csv entries.\n"
exit 0
;;
q) DISP="0";;
f) DESTINATION=${OPTARG};;
esac
done
touch $DESTINATION && echo "Writing logs in $DESTINATION"
if [[ "$DISP" -eq "1" ]]; then
tail -n 0 -f --pid=$$ $DESTINATION &
fi
while [[ "$RUNME" -eq "1" ]]; do
RES=$(nslookup google.com)
if [[ "$?" -ne "0" ]]; then
echo "$(date --iso-8601=seconds), 0, DOWN" >> $DESTINATION
else
echo "$(date --iso-8601=seconds), 1, UP" >> $DESTINATION
fi
sleep 1
done
less $DESTINATION
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment