feat(user/ping_offline.sh):Add script to ping until it succeeds once
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Mon, 20 Feb 2023 22:36:13 +0000 (22:36 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Mon, 20 Feb 2023 22:36:13 +0000 (22:36 +0000)
- Note: the script is meant to mark the time when internet
  connectivity is reestablished.

- doc(user/ping_offline.sh.org):Add docs

- doc(user/template.org):Add template for future executable
  documentation.

doc/user/ping_offline.sh.org [new file with mode: 0644]
doc/user/template.org [new file with mode: 0644]
user/ping_offline.sh [new file with mode: 0755]

diff --git a/doc/user/ping_offline.sh.org b/doc/user/ping_offline.sh.org
new file mode 100644 (file)
index 0000000..6b96e46
--- /dev/null
@@ -0,0 +1,38 @@
+* ping_offline.sh documentation
+
+#+TITLE: ping_offline.sh documentation
+#+AUTHOR: Steven Baltakatei Sandoval
+#+DATE:2023-02-20
+#+EMAIL:baltakatei@gmail.com
+#+LANGUAGE: en
+#+OPTIONS: toc:nil
+
+Created by [[https://baltakatei.com][Steven Baltakatei Sandoval]] on
+2023-02-20T22:27+00
+under a [[https://creativecommons.org/licenses/by-sa/4.0/][CC BY-SA 4.0]] (🅭🅯🄎4.0) license and last updated on
+2023-02-20T22:34+00
+
+** Summary
+
+~ping_offline.sh~ is a small Bash script meant to indicate when the
+machine it runs on is able to ping a remote server.
+
+** Versions
+| Version | Description             |
+|---------+-------------------------|
+|   0.0.1 | Initial working script. |
+
+** Background
+Sometimes, my machines are on a network that is temporarily
+disconnected for various reasons. I'd like to know approximately when
+they come back online by pinging a remote server; once a successful
+ping is established, I can stop further pings. However, the ~ping~
+executable available (provided by the package ~iputils-ping~) on my
+Pop!_OS 22.04 LTS machine throws an error if the machine is completely
+offline; therefore, I wrote the script to regularly try the command
+until it succeeds at least once.
+
+** Dependencies
+- ~iputils-ping~ package (Version: 3:20211215-1)
+
+** References
diff --git a/doc/user/template.org b/doc/user/template.org
new file mode 100644 (file)
index 0000000..491153f
--- /dev/null
@@ -0,0 +1,28 @@
+* template
+
+#+TITLE: template
+#+AUTHOR: Steven Baltakatei Sandoval
+#+DATE:YYYY-mm-dd
+#+EMAIL:baltakatei@gmail.com
+#+LANGUAGE: en
+#+OPTIONS: toc:nil
+
+Created by [[https://baltakatei.com][Steven Baltakatei Sandoval]] on
+YYYY-mm-ddTHH:MM+ZZ
+under a [[https://creativecommons.org/licenses/by-sa/4.0/][CC BY-SA 4.0]] (🅭🅯🄎4.0) license and last updated on
+YYYY-mm-ddTHH:MM+ZZ.
+
+** Summary
+
+
+** Versions
+| Version | Description                                     |
+|---------+-------------------------------------------------|
+|         |                                                 |
+
+** Background
+
+
+** References
+- foo
+- bar
diff --git a/user/ping_offline.sh b/user/ping_offline.sh
new file mode 100755 (executable)
index 0000000..e5b7804
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+# Desc:Marks the time when a remote server can be pinged.
+# Depends: GNU Coreutils 8.32 (date, sleep), iputils-ping 3:20211215-1 (ping)
+# Version: 0.0.1
+
+delay=10;
+domain="google.com"
+
+if [[ -n "$1" ]]; then domain="$1"; fi;
+
+printf "%s:STATUS:Starting ping...\n" "$(date -Is)";
+while ! ping -c1 "$domain"; do
+    sleep "$delay";
+done;
+printf "%s:Ping resolved.\n" "$(date -Is)";
+exit 0;