linux - 如何设置 cron 在特定时间只运行一次文件?

如何设置 cron 在特定时间只运行一次文件?一种选择是at但并非所有使用标准托管计划的用户都可以访问它。因此我想知道是否有办法使用 cron

最佳答案

您真的想在 使用。它正是为此目的而制作的。

echo /usr/bin/the_command options | at now + 1 day

但是,如果您没有 at,或者您的托管公司不提供对其的访问权限,您可以让 cron 作业包含确保它只运行一次的代码。

设置一个具有非常具体时间的 cron 条目:

0 0 2 12 * /home/adm/bin/the_command options

下一个/home/adm/bin/the_command 需要确保它只运行一次。

#! /bin/bash

COMMAND=/home/adm/bin/the_command
DONEYET="${COMMAND}.alreadyrun"

export PATH=/usr/bin:$PATH

if [[ -f $DONEYET ]]; then
  exit 1
fi
touch "$DONEYET"

# Put the command you want to run exactly once here:
echo 'You will only get this once!' | mail -s 'Greetings!' me@example.com

https://stackoverflow.com/questions/5473780/

相关文章:

linux - 为什么使用 dd 克隆磁盘时使用 conv=notrunc?

linux - 在 bash 脚本中使用 curl 并获取 curl : (3) Illegal c

linux - Hadoop:«错误:未设置 JAVA_HOME»

python - 如何从 subprocess.Popen() 获取输出。 proc.stdout.

c++ - 在 64 位 Linux 操作系统上编译 32 位程序导致 fatal error

c++ - 在 Linux 中显式导出共享库函数

linux - 如何测试是否存在两个文件?

c - Linux上C中的标准输出线程安全?

linux - 导出在我的 shell 脚本中不起作用

linux - shell 脚本 : Run function from script over s