質問

I have a TP-Link WR703N flashed with openWRT, connected to a one wire DS18B20 temperature sensor. My goal is to get the router to show the current temp. on a web page. I am using digitemp to read the sensor

When i issue the following command:

root@OpenWrt:~# digitemp_DS9097 -a

The reply from digitemp is:

DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Feb 23 02:46:31 Sensor 0 C: 25.44 F: 77.79

I found this example, where a CRON-script with AWK and SED is used to read the c value, and update a HTML-file.

When i try to paste the script to /etc/crontabs/root, some of the qoutation marks are replaced with ... in the VI editor. I tried to use the Nano editor instead, but it just replaces the qoutation marks with ^?^?^. I do not understand AWK as well as I wish, so i have trouble figuring outh wether the author of the script has used wrong qoutation-marks, or if there is another reason me not being able to input the right characters.

Any input would be greatly appreciated.

役に立ちましたか?

解決

It's the formatting of that blog post, it's got non-ASCII quotes. Just edit them to fix.

*/1 * * * * TEMP=$(digitemp_DS9097 -a | grep -i sensor | awk '{print $7}'); sed -i -r "14s,>[^<]*</,>${TEMP}</," /www/index.html

I'm not sure if the rest of the line is right though, my sed doesn't have that -r flag, and the script tries to change line 14 (hence 14s...) which is very picky on whether you copied the html from the blog exactly. I used this instead:

*/1 * * * * TEMP=$(digitemp_DS9097 -a |grep -i sensor | awk '{print $7}');sed -i.bak "s,\\(66cc00.*\">\\)[^<]*</,\\1$TEMP</,"  /www/index.html

which matches on the colour number on the line instead. The extra \\(...\\) are capturing that so that I can use it again in the replacement as \\1.

I've just read the manual for digitemp_DS9097 (http://www.linuxcertif.com/man/1/digitemp_DS9097/) - you'd be better running it as digitemp_DS9097 -q -t 0 -O"%.2C", which gives you the output directly as a single Centigrade number with no need for grep/awk. eg:

*/1 * * * * TEMP=$(digitemp_DS9097 -q -t 0 -O"%.2C");sed -i.bak "s,\\(66cc00.*\">\\)[^<]*</,\\1$TEMP</,"  /www/index.html
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top