这个问题似乎与 a specific programming problem, a software algorithm, or software tools primarily used by programmers 无关.如果您认为该问题将成为 another Stack Exchange site 上的主题,您可以发表评论,说明在哪里可以回答问题。
关闭 2 年前。
如何设置 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/