Last active
January 30, 2024 00:54
-
-
Save porteusconf/3cfa76fb293ae303a0f34714fcca15df to your computer and use it in GitHub Desktop.
Internet connectivity test. Dumb linux or windows shell script that logs to csv file only those pings that fail. Likely ok to leave running for days.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| echo "for each ping that fails, adds one line to csv log file with iso-8601 date and host" | |
| echo "Usage: ./pinglog.sh host-to-ping i.e. ./pinglog.sh google.com " | |
| # to do: if continually fails, don't log each failure, just start and stop of failures. | |
| # i guess something like if previous fail was less than X secs from current, don't log. | |
| while true ; | |
| do | |
| # change -I arg from wlan1 to whatever interface you want to use | |
| ping -c1 -I wlan1 $1 > /dev/null | |
| ### ping -n 1 $1 > /dev/null ### for windows with gitbash (see comment below) | |
| if [ $? -eq 0 ] | |
| then | |
| echo -n "" | |
| else | |
| echo $(date --iso-8601=ns) " , ping-$1-failed" | tee -a pinglog.csv | |
| fi | |
| sleep 5 # change to number of seconds you want between pings | |
| done | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WINDOWS... I looked for equivalent script in windows, but all I found were long obtuse hard-to-read powershell scripts that did not work ;-) like this: https://community.spiceworks.com/topic/2216374-powershell-script-to-continuously-ping-hosts-and-log-failures-with-timestamps. Seems far easier just to run the shell script in a git-bash shell on windows, as shown below
choco install gitIf you don't have admin privs, try the portable git-for-windows at https://git-scm.com/download/win tho you may not get the context-menu per https://stackoverflow.com/questions/74052142/git-without-admin-rights-windows-10~/pinglogsubfolder, then create and runpinglog.shfrom that folder. (Can be run as non-admin)...Note: options for ping in windows are different, like -n 1 for just one ping (instead of -c 1 for ping in linux).