308- 大佬有话说 :
一个shell命令请教
在脚本里面定时运行,精确到毫秒(安卓终端可能不行),不是cron,百度翻烂了找到一个,有概率到时间了不执行,会休眠。求大佬重写一个脚本
otime="16:35: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}
yanzhiling2002 大佬有话说 :
为什么不能设置crontab,专门拿来定时运行脚本的
#!/bin/bash
otime="16:35:01" #定时时间
step=5 #消息间隔步长
echo "The timing time is : ${otime}, the step is ${step}"
while true; do
ctime=$(date +"%H:%M:%S.%3N")#当前时间,精确到毫秒
if [[ "${ctime}" == "${otime}" ]]; then
echo "Current time is ${ctime}. It’s time to execute the task."
# 在这里执行任务
break
else
echo "Current time is ${ctime}. Waiting…"
fi
sleep 0.1# 休眠0.1秒,减少CPU占用
done
netviyin 大佬有话说 :
百度翻烂了…..
我的天啊。。
这种东西怎么去百度用汉语找呢
要用英文去google找
可见,学不会与世界接轨,有多可怕。
308- 大佬有话说 :
netviyin 大佬有话说 : 2023-10-27 19:54
我的天啊。。
这种东西怎么去百度用汉语找呢
目前纯英文去提问水平差了点…在用文心一言,打算用gpt了,
netviyin 大佬有话说 :
308- 大佬有话说 : 2023-10-27 20:24
目前纯英文去提问水平差了点…在用文心一言,打算用gpt了,
不需要句子
喂几个单词就够了
308- 大佬有话说 :
yanzhiling2002 大佬有话说 : 2023-10-27 19:54
为什么不能设置crontab,专门拿来定时运行脚本的
大佬你这命令改的不全吧,定义了变量step但没有引用呀