我正在执行此脚本来检查我的OctoPrint(3d打印机)是否正在冷却。
通过使用
#octocmd status
temps:
bed: actual=26.0, target=0.0, offset=0
tool0: actual=54.9, target=55.0, offset=0
i will get a data like this.
我能够检查它是否正在打印,因为我已经在bash脚本中完成了此操作
/usr/local/bin/octocmd status | grep 'target=200.0, offset=0'
if [ $? == 0 ]; # if target 200; enter if
then
echo "Printing in progress, Script will check back in 5 minutes"
/usr/local/bin/octocmd status
sleep 5m
在冷却期间,我应该看到
tool0: actual=189.3(decreasing), target=0.0, offset=0
但是我一直在尝试使用我的ELSE功能来检查它是否正在冷却。可以说
actual= (**range from 40.0 to 180**), target=0.0, offset=0
因此,我想谦虚地寻求帮助,以了解如何从Actual = XXX中检测任意范围的数据
这是我目前的代码:
while [ 1 ]
do
/usr/local/bin/octocmd status | grep 'target=200.0, offset=0' &> /dev/null # grab string $ remove error
if [ $? == 0 ]; # if target 200; enter if
then
echo "Printing in progress, Script will check back in 5 minutes"
/usr/local/bin/octocmd status
sleep 5m # check every 5 minutes
elif [ -z "/usr/local/bin/octocmd status | /*CHECK IF PRINTER IS COOLING DOWN OR NOT, CHECK ACTUAL=30 ~ 180 */"' 2>&1 /dev/null ];
then
if [ $? == 0 ];
then
#enter here if target is cooled with no print job
/usr/local/bin/octocmd status
fi
done
要完成anubhava的答案,这里是如何将其包括在bash测试中:
if [[ $(/usr/local/bin/octocmd status | awk -F 'actual=|[,(]' '$2 >= 40 && $2 <= 180 {print 1}') ]]
then
echo "OK"
else
echo "Not OK"
fi
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句