2016-03-05 81 views
0

我有下面的代碼,不幸的是它給出了以下結果。我不明白的東西。有誰知道我做錯了什麼?該代碼用於將數據傳輸到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' –

回答

0

看起來你在這一行有一個額外的$

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

試着改變它

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

,看看它是否工作。