Linux:在代码中输出错误

问题描述:

我有下面的代码,不幸的是它给出了以下结果。我不明白的东西。有谁知道我做错了什么?该代码用于将数据传输到Domoticz(一个运行在Linux上的开源Domotica系统)。Linux:在代码中输出错误

cat: $: No such file or directory 
HTTP/1.1 401 Unauthorized 
Content-Length: 91 
Content-Type: text/html 
Set-Cookie: SID=none; path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT 

代码:

#!/bin/bash 

# Domoticz server 
SERVER="192.168.0.xxx:8080" 

# DHT IDX 
# le numéro de l IDX dans la liste des peripheriques 
DHTIDX="25" 
#DHTPIN 
# LE GPIO ou est connecte le DHT11 
DHTPIN="27" 

# si vous avez un DHT22 modifiez plus bas sur la ligne Adafruit_DHT 11 par Adafruit_DHT 22 
# TMPFILE : chemin pour fichier temporaire a placer dans le RAMDRIVE pour eviter les 
# ecritures sur la SD card 
# sinon chemin ou sera ecrit le fichier contenant les temperature 
# /tmp/temper.txt est un bon choix si pas de RAMDRIVE installe 
# consultez www.easydomoticz.com pour tout savoir 

TMPFILE="/var/tmp/temper.txt" 
# modif de patrick du 08/03/15 pour interroger que 5 fois maxi 
cpt=0 
while [ $cpt -lt 6 ] 
do 
TEMP="" 
sleep 5 
sudo nice -20 ./Adafruit_Python_DHT/examples/AdafruitDHT.py 22 $DHTPIN > $TMPFILE 
TEMP=$(cat $TMPFILE|grep Temp |awk '{print $3}') 
if [ $TEMP ] 
then 
TEMP=$(cat $TMPFILE|grep Temp |awk '{print $3}') 
HUM=$(cat $ $TMPFILE |grep Temp |awk '{print $7}') 
#echo $TEMP 
#echo $HUM 
# Send data 
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2" 
TEMP="" 
HUM="" 
rm $TMPFILE 
exit 0 
fi 
#echo $cpt 
cpt=$(($cpt+1)) 
done 
exit 1 

非常感谢你提前!

+0

此文件是否存在? '/ var/tmp中/ temper.txt' –

看起来你在这一行有一个额外的$

HUM=$(cat $ $TMPFILE |grep Temp |awk '{print $7}') 

试着改变它

HUM=$(cat $TMPFILE |grep Temp |awk '{print $7}') 

,看看它是否工作。