在特定时间运行命令
我正在尝试在特定时间运行命令。我查看了“at”命令,但我不知道如何让它工作......
这就是我所做的:
at 1843 (Enter)
php /run/this/script.php (Ctrl+D)
但是如何在 bash 脚本中执行此操作?我的意思是,我需要按 Enter 和“Ctrl+D”来设置延迟...如何在脚本中执行此操作?
任何建议都非常欢迎。
提前致谢,
I'm trying to run a command at a specific time. I've looked at the "at" command, but I don't know how to get it working...
Here's what I do:
at 1843 (Enter)
php /run/this/script.php (Ctrl+D)
But how do I do this in a bash script? I mean, I need to press enter and "Ctrl+D" to set up the delay... How to do this in a script?
Any suggestions most welcome.
Thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以将命令回显到
at
作为输入:You can echo your command into
at
as input:您可以尝试以下操作:
编辑 如果您想要运行 Firefox,请尝试以下操作:
You could try this:
edit if what you want to do is run Firefox, try this:
在 bash 或 zsh 中,您可以说
如果失败,您需要使用此处的文档:
您可能还想查看 cron 来定期安排工作;
crontab
条目看起来像(编辑:哎哟,有助于回忆
at
的版本。我认为这可能是本地 mod。)In
bash
orzsh
you can sayFailing that, you need to use a here document:
You might also want to look into
cron
for regularly scheduled jobs; thecrontab
entry would look like(EDIT: whoops, helps to recall which version of
at
. I think that may have been a local mod.)echo "php /run/this/script.php" | echo "php /run/this/script.php" | 18:43
echo "php /run/this/script.php" | at 18:43
我工作的系统(Ubuntu、RHEL)默认没有安装 at 命令,而且我没有安装新软件的权限,所以我使用结合 bash 和 awk 的脚本来实现at 功能如下:
./atReplacement.sh $HOUR $MIN; [OTHER_COMMANDS]
The at command is not installed by default to the systems I work (Ubuntu, RHEL) and I don't have permissions to install new software, so I use scripts that combine bash and awk in order to achieve the at functionality as follows:
./atReplacement.sh $HOUR $MIN; [OTHER_COMMANDS]