linux - 在 *nix 上有没有办法在未来的日期和时间触发进程?

标签 linux scheduled-tasks

我希望允许用户输入日期和时间以通过 PHP 发送群发电子邮件,尽管我认为最好使用 *nix 命令来触发 PHP 进程。我想知道 *nix 上是否有一种方法可以做到这一点,而无需添加每 15 分钟运行一次的 cronjob 来检查是否有大量电子邮件要发送。这并不是说这是一个密集的过程,但如果添加和管理 cronjob 会更漂亮。我认为这有点类似于 Windows 计划任务,它有一个结束日期,如果没有再次计划则设置为删除。

最佳答案

您正在寻找 at命令。

at [options] time [date]

Execute commands at a specified time and optional date. The commands are read from standard input or from a file. (See also batch.) End input with EOF. time can be formed either as a numeric hour (with optional minutes and modifiers) or as a keyword. It can contain an optional date, formed as a month and date, a day of the week, or a special keyword (today or tomorrow). An increment can also be specified.

The at command can always be issued by a privileged user. Other users must be listed in the file /etc/at.allow if it exists; otherwise, they must not be listed in /etc/at.deny. If neither file exists, only a privileged user can issue the command.

In typical usage, you run at and input commands that you want executed at a particular time, followed by EOF.

$ at 1:00 am tomorrow at> ./total_up > output at> mail joe < output at> Entered by pressing Ctrl-D job 1 at 2003-03-19 01:00

The two commands could also be placed in a file and submitted as follows:

$ at 1:00 am tomorrow < scriptfile

关于linux - 在 *nix 上有没有办法在未来的日期和时间触发进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/716782/

相关文章:

c++ - 如何在 Linux 中运行 FlashWindow?

c# - Mono 中的 HTTP 监听器不读取 HTTP 请求

linux - 如果只提供了名字,我将如何使用 sed 更改某人的生日?

python - 无法让 subprocess.call 在我的 python 脚本中执行命令

windows - 执行批处理文件时出现 `The application failed to initialize properly`/3221225794 错误

带完成检查的java cron解决方案

sql - 如果 SQL Server 作业已经在运行,它会跳过计划的运行吗?

java - 如何每小时调用一次函数?另外,我怎样才能循环这个?

c - Linux C : upon receiving a signal, 是否可以知道发送者的PID?

python - 每天运行一次 Python 脚本