## loop sleep code ##
#otime="16:35:01" #定时时间
otime="10:00:01" #定时时间
ctime=`date +"%H:%M:%S"` #当前时间
step=5 #消息间隔步长
echo "The timing time is : "${otime}, "the current time is : "${ctime} " the step is "${step}
while [[ "${ctime}" != "${otime}" ]]
do
sleep 1
ctime=`date +"%H:%M:%S"`
mi=`date +"%M"` #分钟
sec=`date +"%S"` #秒
rs=`expr ${mi} % ${step}` #分钟与间隔取余
if [ ${rs} = 0 ] && [ ${sec} = "01" ]
then
echo -e "current time is "`date +"%H:%M:%S"` " wait a few minutes."
#else
#echo "sleep 1 second : "`date +"%H:%M:%S"` " -- M: ${mi} S: ${sec} not !"
fi
done
echo "ctime:"${ctime} " eq otime:"${otime}
## loop sleep code ##
shell等待到指定时间执行任务
于 2021-12-27 19:47:03 首次发布
这段代码实现了一个定时任务,比较当前时间和设定的时间,当达到指定时间时触发提醒,间隔时间为5分钟。主要用于等待某一特定时间点的应用场景。
1811

被折叠的 条评论
为什么被折叠?



