]> git.sthu.org Git - shutils.git/commitdiff
Add ifonline
authorStefan Huber <shuber@sthu.org>
Wed, 12 Jun 2019 07:56:02 +0000 (09:56 +0200)
committerStefan Huber <shuber@sthu.org>
Wed, 12 Jun 2019 07:56:02 +0000 (09:56 +0200)
ifonline [new file with mode: 0755]

diff --git a/ifonline b/ifonline
new file mode 100755 (executable)
index 0000000..5a26215
--- /dev/null
+++ b/ifonline
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+usage() {
+       cat << EOF
+Usage:
+ $0 [OPTIONS]
+ $0 -h
+ $0 -c "echo 'online'"
+
+OPTIONS:
+  -h            Show this text
+  -c CMD        Command to execute if online
+EOF
+}
+
+CMD=""
+
+while getopts "hc:" OPTION; do
+    
+       case "$OPTION" in
+               h)
+                       usage
+                       exit
+                       ;;
+               c)
+                       CMD=$OPTARG
+                       ;;
+       esac
+done
+
+if [ -z "$CMD" ]; then
+    echo "No command given."
+    usage
+    exit 2
+fi
+
+if ping -c1 8.8.8.8 2>&1 >/dev/null; then
+    $CMD
+fi