感谢您的帮助!
我想要一个 shell 脚本从 txt 文件中读取最后一个值。我已经从 python 脚本中得到了这个(另一个脚本),但这在 shell 脚本中不起作用。我在这里和那里(在stackoverflow上)找到了一些帮助脚本部分但我无法让它工作。
如何将 txt 文件 (temper.txt) 中的最后一个值读入 shell 脚本?
txt文件:
1
2
3
4
5
6
7
外壳脚本:
#!/bin/bash
# Domoticz server
SERVER="192.168.0.30:8080"
# IDX DHT
# The number of the IDX in the list of peripherals
DHTIDX="1"
# temp file with the counting
TMPFILE="/var/tmp/temper.txt"
# old piece of the script. not used
#sudo nice -20 Adafruit_DHT 2302 $DHTPIN > $TMPFILE
# 5 seconds for testing
sleep 5
# piece of the script where I want to read the last value form the TEMPFILE!
PULS=$(cat $TMPFILE|grep .... last value... |awk '.... last value ....' |sed -r 's/^.*=//' | sed -r 's/\*//')
echo "PULS: $PULS"
# send data
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command¶m=udevice&idx=$DHTIDX&nvalue=0&svalue=$PULS"
PULS=""
#rm $TMPFILE
exit 0
fi
echo "CPT: $cpt"
cpt=$(($cpt+1))
done
exit 1