【问题标题】:Linux: Error output in codeLinux:代码中的错误输出
【发布时间】:2016-03-05 06:55:21
【问题描述】:

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

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

提前非常感谢您!

【问题讨论】:

  • 这个文件存在吗? /var/tmp/temper.txt

标签: linux temp


【解决方案1】:

您在这一行中似乎多了一个$

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

试试改成

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

看看它是否有效。

【讨论】:

    猜你喜欢
    • 2017-04-29
    • 2016-06-27
    • 1970-01-01
    • 2019-01-12
    • 2020-12-07
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 2012-02-04
    相关资源
    最近更新 更多