From 0abc0ea1cd7e0cf357daba5754f94f8f5b0b6856 Mon Sep 17 00:00:00 2001 From: Charles Han Date: Wed, 18 Oct 2023 20:35:18 +0800 Subject: [PATCH] Fix: sysmonitor limit input paramter -m --- .../detect/sched/sysmonitor/sysmonitor.sh | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/source/tools/detect/sched/sysmonitor/sysmonitor.sh b/source/tools/detect/sched/sysmonitor/sysmonitor.sh index 19084ae7..89a56e54 100755 --- a/source/tools/detect/sched/sysmonitor/sysmonitor.sh +++ b/source/tools/detect/sched/sysmonitor/sysmonitor.sh @@ -35,6 +35,23 @@ monitor() { done } +validate_option_m() { + local input=$1 + + if [[ $input =~ ^[0-9]+([.][0-9]+)?$ ]]; then + if (( $(bc <<< "$input >= 0 && $input <= 100") == 1 )); then + return 0 + else + echo "Only the range of 0 to 100 is valid in: -m " + return 1 + fi + else + echo "Only the positive integer or floating-point number is valid in: -m " + return 1 + fi +} + + while getopts 'm:f:c:i:lh' OPT; do case $OPT in "h") @@ -42,7 +59,11 @@ while getopts 'm:f:c:i:lh' OPT; do exit 0 ;; "m") - maxsys=$OPTARG + if validate_option_m $OPTARG; then + maxsys=$OPTARG + else + exit 1 + fi ;; "f") datafile=$OPTARG -- Gitee