你能把txt文件中的脉冲值输入Shell脚本吗?

2024-05-07 21:40:22 发布

您现在位置:Python中文网/ 问答频道 /正文

谢谢你的帮助!你知道吗

我想要一个shell脚本从txt文件中读取最后一个值。我从python脚本中得到了这个(另一个脚本),但在shell脚本中不起作用。我发现一些帮助脚本部分在这里和那里(在stackoverflow)但我不能得到这个工作。你知道吗

如何从txt文件中读取最后一个值(回火.txt)在shell脚本中?你知道吗

txt文件:

1个

4个

Shell脚本:

#!/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&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$PULS"
PULS=""

#rm $TMPFILE
exit 0
fi
echo "CPT: $cpt"
cpt=$(($cpt+1))
done
exit 1

Tags: 文件ofthetxt脚本servervalueshell