2021年1月1日星期五

Remove "/usr/bin/sensors" from output of Bash script

so i have this Code:

      if type -P sensors 2>/dev/null; then          returnString=`sensors`          #amd          if [[ "${returnString/"k10"}" != "${returnString}" ]] ; then            $SENSORS | grep Tdie | $CUT -d ' ' -f 10 | { echo "{"; cat; echo "}"; } | tr -d '\n'          #intel          elif [[ "${returnString/"core"}" != "${returnString}" ]] ; then            fromcore=${returnString##*"coretemp"}            $ECHO ${fromcore##*Physical}  | $CUT -d ' ' -f 3 | $CUT -c 2-5 | _parseAndPrint          fi        else          $ECHO "[]" | _parseAndPrint        fi  

and the output is:

/usr/bin/sensors  {+31.9°C}  

The desired output is:

{+31.9°C}  

sensors output:

/usr/bin/sensors  nvme-pci-0100  Adapter: PCI adapter  Composite:    +33.9°C  (low  =  -0.1°C, high = +74.8°C)                         (crit = +79.8°C)    k10temp-pci-00c3  Adapter: PCI adapter  Vcore:         1.12 V    Vsoc:        888.00 mV   Tctl:         +31.1°C    Tdie:         +31.1°C    Icore:         8.00 A    Isoc:          5.00 A    

I would really prefer a way to leave "if type -P sensors 2>/dev/null; then" in there, so it can still detect if it is intel or amd, but if there is no way, i will just remove it, because it works, without that check. The line is run in a script file, which can be found here: https://github.com/chibbi/ComputerDashboard/blob/4b4256b08349d2ca9accffc8405d4d82b14f4078/linux_json_api.sh#L134

https://stackoverflow.com/questions/65535280/remove-usr-bin-sensors-from-output-of-bash-script January 02, 2021 at 09:29AM

没有评论:

发表评论