跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 一个shell命令请教
未分類
27 10 月 2023

一个shell命令请教

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但没有引用呀

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具