There are many ways of doing this, depending on your needs.
Example file:
07/17 21:04:01 sndc addr unit 1 : hu P1 (TempLinc) 07/17 21:04:02 sndc func StatusReq : hc P 07/17 21:04:04 rcvi addr unit 15 : hu P15 (TempAck_5) 07/17 21:04:04 rcvi func Preset : level 11 07/17 21:04:04 Temperature = 78 : hu P0 (office_temp) 07/17 21:19:01 sndc addr unit 1 : hu P1 (TempLinc) 07/17 21:19:02 sndc func StatusReq : hc P 07/17 21:19:05 rcvi addr unit 15 : hu P15 (TempAck_5) 07/17 21:19:05 rcvi func Preset : level 11 07/17 21:19:05 Temperature = 78 : hu P0 (office_temp)
#!/bin/bash fil=/home/test.log # Test for existence of the test file if [ -f $fil ] then # Read through the file looking for the word Temperature = while read line do echo $line | grep -q Temperature if [ $? == 0 ]; then mytemp=`echo $line | cut -d = -f2 | cut -d : -f1` echo "Current temperature is: $mytemp" fi done < $fil fi
returns:
Current temperature is: 78 Current temperature is: 78
NOTE: The -f tests that the file exists.
Other options include:
#!/bin/bash fil=/home/temp.log.ttyS0 if [ -f $fil ] then mytemp=`grep Temperature $fil | tail -1 | cut -d = -f2 | cut -d : -f1` echo "Current temperature is: $mytemp" fi