From ffcf6659b79f223bb7749dd9354e8add6e1bb4b1 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Wed, 12 Jun 2019 09:56:02 +0200 Subject: [PATCH] Add ifonline --- ifonline | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 ifonline diff --git a/ifonline b/ifonline new file mode 100755 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 -- 2.39.5