Celsius und Fahrenheit hinzugefügt

This commit is contained in:
Patrick Schindelmann 2019-10-22 08:13:08 +02:00
parent 74cd82923c
commit 494e3ae4f7

View File

@ -20,6 +20,7 @@ HDDTEMP="$(type -P hddtemp)"
PARAMETER="$*" PARAMETER="$*"
WARNING="40" WARNING="40"
CRITICAL="45" CRITICAL="45"
UNIT="c"
function hilfetext(){ function hilfetext(){
cat <<- EOF cat <<- EOF
@ -27,17 +28,20 @@ function hilfetext(){
$(basename "$0") [OPTION...] $(basename "$0") [OPTION...]
Options: Options:
-d | --device -d | --device
--fahrenheit
--celsius (default)
-w | --warning (default: 40) -w | --warning (default: 40)
-c | --critical (default: 50) -c | --critical (default: 50)
-p | --perfdata -p | --perfdata
-h | --help -h | --help
EOF EOF
} }
function ParameterEvaluation(){ function ParameterEvaluation(){
options=$(getopt -o c:d:hpw: --long critical: --long device: --long help --long perfdata --long warning: -- "$@") options=$(getopt -o c:d:hpw: --long fahrenheit --long celsius --long critical: --long device: --long help --long perfdata --long warning: -- "$@")
#Option nicht verfügbar #Option nicht verfügbar
[ "$?" -eq "0" ] || { [ "$?" -eq "0" ] || {
@ -52,6 +56,12 @@ function ParameterEvaluation(){
shift; # The arg is next in position args shift; # The arg is next in position args
DEVICE="$1" DEVICE="$1"
;; ;;
"--celsius")
UNIT="c"
;;
"--fahrenheit")
UNIT="f"
;;
"-w"|"--warning") "-w"|"--warning")
shift; # The arg is next in position args shift; # The arg is next in position args
WARNING="$1" WARNING="$1"
@ -96,7 +106,7 @@ ParameterEvaluation "$0" "$@"
#Debug #Debug
#echo -e "WARNING:\t\"$WARNING\"" #echo -e "WARNING:\t\"$WARNING\""
#echo -e "CRITICAL:\t\"$CRITICAL\"" #echo -e "CRITICAL:\t\"$CRITICAL\""
#echo -e "DEVICE:\t\t\"$DEVICE\"" echo -e "DEVICE:\t\t\"$DEVICE\""
#echo -e "HELP\t\t\"$HELP\"" #echo -e "HELP\t\t\"$HELP\""
#echo -e "PERFDATA\t\t\"$PERFDATA\"" #echo -e "PERFDATA\t\t\"$PERFDATA\""
#echo -e "Alle Args:\t\"$@\"" #echo -e "Alle Args:\t\"$@\""
@ -115,7 +125,14 @@ then
exit 1 exit 1
fi fi
RESULT=$($HDDTEMP $DEVICE) if [ "$UNIT" = "c" ]
then
RESULT=$($HDDTEMP --unit=C $DEVICE)
elif [ "$UNIT" = "f" ]
then
RESULT=$($HDDTEMP --unit=F $DEVICE)
fi
OUTDEV=$(echo "$RESULT" | awk -F: '{print $1}') OUTDEV=$(echo "$RESULT" | awk -F: '{print $1}')
OUTMODEL=$(echo "$RESULT" | awk -F: '{print $2}' | tr -cd '[:print:]') OUTMODEL=$(echo "$RESULT" | awk -F: '{print $2}' | tr -cd '[:print:]')
OUTTEMP=$(echo "$RESULT" | awk -F: '{print $3}') OUTTEMP=$(echo "$RESULT" | awk -F: '{print $3}')