diff --git a/source/tools/detect/sched/sysmonitor/sysmonitor.sh b/source/tools/detect/sched/sysmonitor/sysmonitor.sh index 19084ae734ac1fbbbd895d7d0ed5652c56db0c3d..89a56e54383405c3eb87ce76439f61d4841e2fc5 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