Question

# Program which notifies the User through 'notify-send' when device temperature exceeds the threshold.

#!/bin/bash

Temp=adb shell cat /sys/devices/platform/omap/omap_temp_sensor.0/temperature
if  [ $Temp -gt 42000 ] 
then
notify-send Temperature "$Temp " -i /usr/share/pixmaps/idle.xpm
cvlc  /home/Xme/Desktop/Beep-263732.mp3
else
echo "Exit"
fi

Getting error as

: integer expression expected

I am not getting the data type of $Temp which is reading the data by Device, and how can i compare the integers, i tried if [ [$Temp > 42000] ] did not work.

Was it helpful?

Solution

As we said in the comments, this solved the issue:

Temp=$(adb shell cat /sys/devices/platform/omap/omap_temp_sensor.0/temperature) | grep -o "[0-9]*")

First of all, you were not fetching the number properly. Note that you need to use

Temp=$(command)

While you were using

Temp=command

Then we saw that your input was not integer. I guess there must be some trailing characters. To delete them, I suggest to use grep -o "[0-9]*", which just matches the numbers in the string given. EXamples:

$ echo "23 " | grep -o "[0-9]*"
23
$ echo "as23.22" | grep -o "[0-9]*"
23
22
$ echo "23" | grep -o "[0-9]*"
23
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top