[英]Munin in shell script
I want to use Munin to show the wave of my data. 我想用Munin来展示我的数据浪潮。 I get the data from ttyACM0, it's an Arduino UNO.
我从ttyACM0获取数据,它是一个Arduino UNO。 I use shell script.
我使用shell脚本。 But I got a problem, I cannot ues 'cat /dev/ttyACM0' to get the data.
但是我遇到了问题,我不能'cat / dev / ttyACM0'来获取数据。 Here is the problem, the programme stopped at 'cat /dev/ttyACM0',
这是问题,程序停在'cat / dev / ttyACM0',
+ . /usr/share/munin/plugins/plugin.sh
+ '[' '' = autoconf ']'
+ '[' '' = config ']'
++ cat /dev/ttyACM0
Sometimes there is another problem, it's that 'LINE = $(cat /dev/ttyACM0 | awk -F: '{print $2}')' command not found. 有时会出现另一个问题,就是找不到'LINE = $(cat / dev / ttyACM0 | awk -F:'{print $ 2}')'命令。 Anyone has an idea?
有人有想法吗? Thanks very much.
非常感谢。
Here is a part of my code, 这是我的代码的一部分,
if [ "$1" = "config" ]; then
echo 'graph_title Temperature of board'
echo 'graph_args --base 1000 -l 0'
echo 'graph_vlabel temperature(°C)'
echo 'graph_category temperature'
echo 'graph_scale no'
echo 'graph_period second'
echo 'graph_info This graph shows the temperature of board'
LINE = $(cat /dev/ttyACM0 | awk -F: '{print $2}')
for i in 0 1 2 3 4; do
case $i in
1)
TYPE="Under PCB"
;;
2)
TYPE="HDD"
;;
3)
TYPE="PHY"
;;
4)
TYPE="CPU"
;;
5)
TYPE="Ambience"
;;
esac
name=$(clean_name $TYPE)
if ["$TYPE" != "NA"]; then
echo "temp_$name.label $TYPE";
fi
done
exit 0
fi
LINE = $(cat /dev/ttyACM0 | awk -F: '{print $2}')
for i in 0 1 2 3 4; do
case $i in
1)
TYPE="Under PCB"
VALUE=$(echo "$LINE" | awk '{print $1}')
;;
2)
TYPE="HDD"
VALUE=$(echo "$LINE" | awk '{print $2}')
;;
3)
TYPE="PHY"
VALUE=$(echo "$LINE" | awk '{print $3}')
;;
4)
TYPE="CPU"
VALUE=$(echo "$LINE" | awk '{print $4}')
;;
5)
TYPE="Ambience"
VALUE=$(echo "$LINE" | awk '{print $5}')
;;
esac
name=$(clean_name $TYPE)
if ["$TYPE" != "NA"]; then
echo "temp_$name.value $VALUE";
fi
done
Remove the spaces on either side of =
sign. 删除
=
符号两侧的空格。 They are not permitted in variable assignment. 它们不允许进行变量赋值。
Change it to: 将其更改为:
LINE=$(cat /dev/ttyACM0 | awk -F: '{print $2}')
The problem with the LINE error is that you have spaces around the '=' character. LINE错误的问题是'='字符周围有空格。 It must be
LINE=...
. 它必须是
LINE=...
If /dev/ttyACM0
is a device that does not indicate EOF, then it will wait for more to read and the awk
will wait for an EOF that never comes. 如果
/dev/ttyACM0
是一个不指示EOF的设备,那么它将等待更多的读取,并且awk
将等待从未到来的EOF。 What exactly do you expect /dev/ttyACM0
to produce? 你期望
/dev/ttyACM0
到底产生什么? What happens if you type cat /dev/ttyACM0
on the console? 如果在控制台上键入
cat /dev/ttyACM0
会发生什么?
Further note the useless use of cat. 进一步注意猫的无用。 Better use
更好用
LINE=$(awk -F: '{print $2}' /dev/ttyACM0)
And you must add space in if ["$TYPE" != "NA"]; then
if ["$TYPE" != "NA"]; then
你必须添加空格if ["$TYPE" != "NA"]; then
if ["$TYPE" != "NA"]; then
so it reads if ["$TYPE" != "NA"]; then
就读了
if [ "$TYPE" != "NA" ]; then
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.