在特定时间运行命令

发布于 2024-11-02 13:07:45 字数 251 浏览 7 评论 0原文

我正在尝试在特定时间运行命令。我查看了“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

凉城已无爱 2024-11-09 13:07:45

您可以将命令回显到 at 作为输入:

echo "/usr/bin/php /run/this/script.php" | at 18:43

You can echo your command into at as input:

echo "/usr/bin/php /run/this/script.php" | at 18:43
游魂 2024-11-09 13:07:45

您可以尝试以下操作:

at 1843 <<_EOF_
php /run/this/script.php
_EOF_

编辑 如果您想要运行 Firefox,请尝试以下操作:

at 1843 <<_EOF_
DISPLAY=:0.0 /usr/bin/firefox
_EOF_

You could try this:

at 1843 <<_EOF_
php /run/this/script.php
_EOF_

edit if what you want to do is run Firefox, try this:

at 1843 <<_EOF_
DISPLAY=:0.0 /usr/bin/firefox
_EOF_
兔小萌 2024-11-09 13:07:45

在 bash 或 zsh 中,您可以说

at 1843 <<< 'php /run/this/script.php'

如果失败,您需要使用此处的文档:

at 1843 <<EOF
php /run/this/script.php
EOF

您可能还想查看 cron 来定期安排工作; crontab 条目看起来像

43 18 * * * php /run/this/script.php

(编辑:哎哟,有助于回忆 at 的版本。我认为这可能是本地 mod。)

In bash or zsh you can say

at 1843 <<< 'php /run/this/script.php'

Failing that, you need to use a here document:

at 1843 <<EOF
php /run/this/script.php
EOF

You might also want to look into cron for regularly scheduled jobs; the crontab entry would look like

43 18 * * * php /run/this/script.php

(EDIT: whoops, helps to recall which version of at. I think that may have been a local mod.)

殊姿 2024-11-09 13:07:45

echo "php /run/this/script.php" | echo "php /run/this/script.php" | 18:43

echo "php /run/this/script.php" | at 18:43

同展鸳鸯锦 2024-11-09 13:07:45

我工作的系统(Ubuntu、RHEL)默认没有安装 at 命令,而且我没有安装新软件的权限,所以我使用结合 bash 和 awk 的脚本来实现at 功能如下:

#! /bin/bash

res=""
while [ ! $res ]; do

    res=$( date | awk -v hour=$1 -v min=$2 '{ 

        split($4, tmp, ":" );

        if( (tmp[1] == hour) && (tmp[2] == min) )
        {
            print "ok";   
        }
        else
        {
            print "";
        }

    }' )

done

./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:

#! /bin/bash

res=""
while [ ! $res ]; do

    res=$( date | awk -v hour=$1 -v min=$2 '{ 

        split($4, tmp, ":" );

        if( (tmp[1] == hour) && (tmp[2] == min) )
        {
            print "ok";   
        }
        else
        {
            print "";
        }

    }' )

done

./atReplacement.sh $HOUR $MIN; [OTHER_COMMANDS]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文