From: Stefan Huber Date: Wed, 12 Jun 2019 07:56:02 +0000 (+0200) Subject: Add ifonline X-Git-Url: https://git.sthu.org/?a=commitdiff_plain;h=ffcf6659b79f223bb7749dd9354e8add6e1bb4b1;p=shutils.git Add 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