将温度从机智的 pi 2 导出到日志文件



我已经在我的RPI2上安装了一个机智的pi 3 但是我想将临时文件从中导出到spcific文件

我可以运行一个名为 witty.sh 的脚本,然后我需要按 8 或 Ctrl + C 退出

>>> Current temperature: 33.50°C / 92.3°F
>>> Your system time is: Sat 01 Jul 2017 20:29:46 CEST
>>> Your RTC time is:    Sat 01 Jul 2017 20:29:46 CEST
Now you can:
1. Write system time to RTC
2. Write RTC time to system
3. Synchronize time
4. Schedule next shutdown [25 15:04:00]
5. Schedule next startup  [25 15:05:00]
6. Choose schedule script
7. Reset data...
8. Exit
What do you want to do? (1~8)

我想要的只是导出第一行。

我试过了

sudo ./wittyPi.sh | grep Current | awk '{ print $4 }' > temp.log

但它问我一个数字,然后在 temp 中给出温度.log

最后是否可以插入一些额外的代码到generete Ctrl + C或sometinhg?

只需使用 here 字符串来提供输入:

$ cat tst.sh
echo "Type something:" >&2
read foo
echo "$foo"
$ ./tst.sh <<<stuff | sed 's/u/X/'
Type something:
stXff

如果你的 shell 不支持 here 字符串,请改用 here 文档:

$ ./tst.sh <<EOF | sed 's/u/X/'
> stuff
> EOF
Type something:
stXff

所以你会这样做(当你使用 awk 时,你永远不需要 grep(:

sudo ./wittyPi.sh <<<8 | awk '/Current/{ print $4 }' > temp.log

或:

sudo ./wittyPi.sh <<<8 | awk 'NR==1{ print $4 }' > temp.log

也许更好的方法是查看"utilities.sh"文件中的 get_temperature(( 函数,看看它是如何实现的。它只涉及一些I2C通信。

最新更新