击:睡眠,直到特定的时间/日期 [英] Bash: Sleep until a specific time/date

查看:100
本文介绍了击:睡眠,直到特定的时间/日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的bash脚本睡觉,直到一个特定的时间。所以,我要像休眠它没有任何间隔,但结束时间和休眠,直到随后的命令。

I want my bash script to sleep until a specific time. So, I want a command like "sleep" which takes no interval but an end time and sleeps until then.

在-daemon不是解决办法,因为我需要阻止正在运行的脚本直到特定的日期/时间。

The "at"-daemon is not a solution, as I need to block a running script until a certain date/time.

有没有这样的命令?

推荐答案

正如奥特洛程序员所提到的,我认为,解决方案只是睡了正确的秒数。

As mentioned by Outlaw Programmer, I think the solution is just to sleep for the correct number of seconds.

要在bash做到这一点,做到以下几点:

To do this in bash, do the following:

current_epoch=$(date +%s)
target_epoch=$(date -d '01/01/2010 12:00' +%s)

sleep_seconds=$(( $target_epoch - $current_epoch ))

sleep $sleep_seconds

这篇关于击:睡眠,直到特定的时间/日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆