From d41ba60101fd4b41d7aef9f20be7f96cea0be41d Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 1 Jun 2023 16:15:54 +0200 Subject: [PATCH] Refactor command line options for all scripts to include a help option. --- check-disk.sh | 10 +++++++--- check-dummy.sh | 10 +++++++--- check-load.sh | 10 +++++++--- check-md.sh | 10 +++++++--- check-mem.sh | 10 +++++++--- check-systemctl-service.sh | 10 +++++++--- check-url.sh | 10 +++++++--- check-webcron.sh | 10 +++++++--- 8 files changed, 56 insertions(+), 24 deletions(-) diff --git a/check-disk.sh b/check-disk.sh index 9cde693..782c315 100644 --- a/check-disk.sh +++ b/check-disk.sh @@ -3,13 +3,14 @@ # #/ #/ Usage: -#/ check-disk.sh --warning= --critical= +#/ check-disk.sh --warning= --critical= --help #/ #/ Checks the disk usage #/ #/ Options: #/ -w, --warning= The level of when to trigger a warning (level=loadavg/nproc) #/ -c, --critical= The level of when to trigger a critical warning (level=loadavg/nproc) +#/ -h, --help Display this help message #/ #/ Exit Codes: #/ 0 Everything OK @@ -25,8 +26,8 @@ Usage() { GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS=w:c: - LONGOPTS=warning:,critical: + OPTIONS=w:c:h + LONGOPTS=warning:,critical:,help # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -54,6 +55,9 @@ GetOptions() { crit="$2" shift 2 ;; + -h|--help) + Usage + exit 0; --) shift break diff --git a/check-dummy.sh b/check-dummy.sh index a76a770..36640b1 100644 --- a/check-dummy.sh +++ b/check-dummy.sh @@ -3,7 +3,7 @@ # #/ #/ Usage: -#/ check-dummy.sh [--ok|--warning|--critical] +#/ check-dummy.sh [--ok|--warning|--critical] --help #/ #/ Does not check anything. #/ @@ -12,6 +12,7 @@ #/ -w, --warning Trigger a warning #/ -c, --critical Trigger a critical warning #/ -u, --unknown Trigger a unknown status +#/ -h, --help Display this help message #/ #/ #/ Exit Codes: @@ -27,8 +28,8 @@ Usage() { GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS='owcu' - LONGOPTS='ok,warning,critical,unknown' + OPTIONS='owcuh' + LONGOPTS='ok,warning,critical,unknown,help' # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -67,6 +68,9 @@ GetOptions() { rmsg="UNKNOWN" shift ;; + -h|--help) + Usage + exit 0; --) shift break diff --git a/check-load.sh b/check-load.sh index 8450e53..fbbfb03 100644 --- a/check-load.sh +++ b/check-load.sh @@ -3,7 +3,7 @@ # #/ #/ Usage: -#/ check-load.sh --warning= --critical= --average= +#/ check-load.sh --warning= --critical= --average= --help #/ #/ Checks the system load #/ @@ -11,6 +11,7 @@ #/ -w, --warning= The level of when to trigger a warning (level=loadavg/nproc) #/ -c, --critical= The level of when to trigger a critical warning (level=loadavg/nproc) #/ -a, --average= Which avarage to use for the load level (possible values are 1, 5 and 15) +#/ -h, --help Display this help message #/ #/ Exit Codes: #/ 0 Everything OK @@ -26,8 +27,8 @@ Usage() { GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS=w:c:a: - LONGOPTS=warning:,critical:,avarage: + OPTIONS=w:c:a:h + LONGOPTS=warning:,critical:,avarage:,help # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -63,6 +64,9 @@ GetOptions() { check="$2" shift 2 ;; + -h|--help) + Usage + exit 0; --) shift break diff --git a/check-md.sh b/check-md.sh index ba960b7..9e8cb24 100644 --- a/check-md.sh +++ b/check-md.sh @@ -3,13 +3,14 @@ # #/ #/ Usage: -#/ check-md.sh --warning= --critical= +#/ check-md.sh --warning= --critical= --help #/ #/ Checks the raid-device status #/ #/ Options: #/ -w, --warning= The events of when to trigger a warning (comma-separated) #/ -c, --critical= The events of when to trigger a critical warning (comma-separated) +#/ -h, --help Display this help message #/ #/ Possible events #/ - clean @@ -31,8 +32,8 @@ Usage() { GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS=w:c: - LONGOPTS=warning:,critical: + OPTIONS=w:c:h + LONGOPTS=warning:,critical:,help # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -65,6 +66,9 @@ GetOptions() { IFS=$OLDIFS shift 2 ;; + -h|--help) + Usage + exit 0; --) shift break diff --git a/check-mem.sh b/check-mem.sh index 857b6b0..34c8d82 100644 --- a/check-mem.sh +++ b/check-mem.sh @@ -3,13 +3,14 @@ # #/ #/ Usage: -#/ check-memory.sh --warning= --critical= +#/ check-memory.sh --warning= --critical= --help #/ #/ Checks the memory usage #/ #/ Options: #/ -w, --warning= The level of when to trigger a warning (level=loadavg/nproc) #/ -c, --critical= The level of when to trigger a critical warning (level=loadavg/nproc) +#/ -h, --help Display this help message #/ #/ Exit Codes: #/ 0 Everything OK @@ -25,8 +26,8 @@ Usage() { GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS=w:c: - LONGOPTS=warning:,critical: + OPTIONS=w:c:h + LONGOPTS=warning:,critical:,help # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -54,6 +55,9 @@ GetOptions() { crit="$2" shift 2 ;; + -h|--help) + Usage + exit 0; --) shift break diff --git a/check-systemctl-service.sh b/check-systemctl-service.sh index b27fe44..18aa600 100644 --- a/check-systemctl-service.sh +++ b/check-systemctl-service.sh @@ -3,10 +3,11 @@ # #/ #/ Usage: -#/ check-systemctl-service.sh +#/ check-systemctl-service.sh --help #/ #/ Options: #/ -u, --user Check for running within current user +#/ -h, --help Display this help message #/ #/ Checks if a systemd unit is active #/ @@ -23,8 +24,8 @@ Usage() { GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS=u - LONGOPTS=user + OPTIONS=uh + LONGOPTS=user,help # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -48,6 +49,9 @@ GetOptions() { user='--user' shift 1 ;; + -h|--help) + Usage + exit 0; --) shift break diff --git a/check-url.sh b/check-url.sh index 217935c..aaa283e 100644 --- a/check-url.sh +++ b/check-url.sh @@ -3,7 +3,7 @@ # #/ #/ Usage: -#/ check-url.sh --proxy= --warning= --critical= +#/ check-url.sh --proxy= --warning= --critical= --help #/ #/ Checks if URL is available #/ @@ -11,6 +11,7 @@ #/ -p, --proxy= The proxy server to use #/ -w, --warning= The amount of response time to trigger a warning (in sec) #/ -c, --critical= The amount of response time to trigger a critcal warning (in sec) +#/ -h, --help Display this help message #/ #/ Exit Codes: #/ 0 Everything OK @@ -26,8 +27,8 @@ Usage() { GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS=p:w:c: - LONGOPTS=proxy:,warning:,critical: + OPTIONS=p:w:c:h + LONGOPTS=proxy:,warning:,critical:,help # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -59,6 +60,9 @@ GetOptions() { crit="$2" shift 2 ;; + -h|--help) + Usage + exit 0; --) shift break diff --git a/check-webcron.sh b/check-webcron.sh index b4ab1e7..0e28f98 100644 --- a/check-webcron.sh +++ b/check-webcron.sh @@ -3,7 +3,7 @@ # #/ #/ Usage: -#/ check-webcron.sh --proxy= [--daemon] --warning= --critical= +#/ check-webcron.sh --proxy= [--daemon] --warning= --critical= --help #/ #/ Checks webcron jobs #/ @@ -12,6 +12,7 @@ #/ -d, --daemon When no daemon is running trigger a critical warning #/ -w, --warning= The ratio of failed jobs to trigger a warning (1 = all jobs; 0.5 = half of all jobs) #/ -c, --critical= The ratio of failed jobs to trigger a critcal warning (1 = all jobs; 0.5 = half of all jobs) +#/ -h, --help Display this help message #/ #/ Exit Codes: #/ 0 Everything OK @@ -27,8 +28,8 @@ Usage() { GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS=p:dw:c: - LONGOPTS=proxy:,daemon,warning:,critical: + OPTIONS=p:dw:c:h + LONGOPTS=proxy:,daemon,warning:,critical:,help # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -63,6 +64,9 @@ GetOptions() { crit="$2" shift 2 ;; + -h|--help) + Usage + exit 0; --) shift break