Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash比较两个数字在一段时间内的变化_Bash_Time_Compare - Fatal编程技术网

bash比较两个数字在一段时间内的变化

bash比较两个数字在一段时间内的变化,bash,time,compare,Bash,Time,Compare,我想知道的是这个。我得到气压读数,我想为其创建警报。我有一个工作的,但我想添加一个时间比较,以更准确。 例如,如果“X”数字在5分钟内降到“X”数字以下,那么就做些什么 谢谢收听 您可以执行以下操作: #!/bin/bash while [ 0 ] do oldval=`cat reading` # Suppose that reading is the file where readings are updated sleep 5m # sleeps for 5 minutes newva

我想知道的是这个。我得到气压读数,我想为其创建警报。我有一个工作的,但我想添加一个时间比较,以更准确。 例如,如果“X”数字在5分钟内降到“X”数字以下,那么就做些什么


谢谢收听

您可以执行以下操作:

#!/bin/bash
while [ 0 ]
do

oldval=`cat reading` # Suppose that reading is the file where readings are updated
sleep 5m # sleeps for 5  minutes
newval=`cat reading`

if (( $newval < $oldval-5 ))
    then
       echo "$( date ) : Beep Beep " | tee -a barrolog
       #above steps prints the output as well as append it to a log file
    else
       echo "$( date ) : No change " | tee -a barrolog
fi

done 
# The script never reaches this point.
#/bin/bash
而[0]
做
oldval=`cat reading`#假设reading是更新读数的文件
睡5分钟#睡5分钟
newval=`cat reading`
如果($newval<$oldval-5))
然后
echo“$(日期):嘟嘟嘟嘟”| T恤-巴罗洛格
#上述步骤打印输出并将其附加到日志文件中
其他的
echo“$(日期):无变化”| tee-a barrolog
fi
完成
#脚本永远不会达到这一点。

脚本将检查相对于上一个脚本的读数。您可能希望将读数与固定值进行比较。

这只是一个友好的提示,您可能希望阅读本页:因此您可以始终确保您的问题易于回答且尽可能清楚。请确保包括您为解决问题所做的任何努力,以及在尝试这些修复时发生的情况。另外,不要忘记显示代码和任何错误消息!另外,在发布问题时,一定要问一个问题。