0

# 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.

WEshruth
  • 769
  • 3
  • 16
  • 32
  • @fedorqui : Fixed and posted, can anyone please help me out with this. – WEshruth Sep 12 '13 at 11:03
  • What if you do `Temp=$(adb shell cat /sys/devices/platform/omap/omap_temp_sensor.0/temperature)`? – fedorqui Sep 12 '13 at 11:06
  • I am using `Panda board` which is a Mobile Device, through the above command i am reading Temperature, that gives me device current temperature ( Ex:42000 ), i need to compare that value with threshold and if that Temperature exceeds, program will notify me through notify-send command – WEshruth Sep 12 '13 at 11:27
  • Yes, I understood that. What I suggested is to replace Temp definition with `Temp=$(adb shell cat /sys/devices/platform/omap/omap_temp_sensor.0/temperature)` – fedorqui Sep 12 '13 at 11:34
  • Getting same error, `: integer expression expected` – WEshruth Sep 12 '13 at 11:58
  • What kind of data do you get? Are you sure it is just an integer? Try to `Temp=$(adb shell cat /sys/devices/platform/omap/omap_temp_sensor.0/temperature) | grep -o "[0-9]*")` so the output will be just numbers, and hence an integer. – fedorqui Sep 12 '13 at 11:59
  • @fedorqui, Problem solved!! Thank you very much , If possible can you explain what that `grep -o "[0-9]*"` did, is this conversion to Integer? – WEshruth Sep 12 '13 at 12:10

1 Answers1

1

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
fedorqui
  • 275,237
  • 103
  • 548
  • 598