I am trying to store CPU temperature in a variable. I am not sure how to use sed so I am mostly using grep. Here is what I have tried so far, but I am getting syntax error. I am also getting error during the comparison, but I thing it is because CPUTEMP is not resolving.
#!/bin/bash
#
CPUTEMP = $((/usr/bin/sensors k10temp-pci-00c3 | grep temp1 | awk '{print \$2}' | grep -o '[0-9,.]\+'))
if [ "$CPUTEMP" -le 40 ]; then
echo "OK - CPU idle"
exit 0
...
...
fi
What am I doing wrong here? Thank you!
I read some more online and was able to solve my problem. There were four problems in my script.
(all of these problems above are in the same line where CPUTEMP is assigned a value)
Here is the working code:
#!/bin/bash
#
CPUTEMP=$(/usr/bin/sensors k10temp-pci-00c3 | grep temp1 | awk '{print $2}' | grep -o '[0-9,.]\+')
if (( $(echo "$CPUTEMP <= 40" | bc -l) ))
then
echo "OK - CPU idle"
exit 0
...
...
fi
Thank you for your help guys!