]> zdv2.bktei.com Git - BK-2020-03.git/blob - user/ping_offline.sh
feat(user/gthumb/gthumb-analyze.sh):Get stats on selected images
[BK-2020-03.git] / user / ping_offline.sh
1 #!/bin/bash
2 # Desc:Marks the time when a remote server can be pinged.
3 # Depends: GNU Coreutils 8.32 (date, sleep), iputils-ping 3:20211215-1 (ping)
4 # Version: 0.1.0
5
6 delay=10;
7 domain="google.com"
8
9 yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
10 die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
11 must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
12
13 if [[ -n "$1" ]]; then domain="$1"; fi;
14
15 SECONDS=0;
16 printf "%s:STATUS:Starting ping...\n" "$(date -Is)";
17 while [[ ! noPing == "true" ]]; do
18 printf "%s:" "$(date -Is)"; # prepend line with date
19 ping -c1 "$domain"; pingExitCode="$?"; # perform ping
20
21 if [[ "$pingExitCode" -eq 0 ]]; then
22 # Case if ping succeeded
23 printf "%s:Ping resolved after $SECONDS seconds.\n" "$(date -Is)";
24 exit 0;
25 elif [[ "$pingExitCode" -eq 1 ]]; then
26 sleep "$delay";
27 continue;
28 else
29 die "FATAL:Unknown error.";
30 exit 1;
31 fi;
32 done;
33
34 yell "ERROR:Here be dragons.";
35 exit 1;