【问题标题】:Automatically launching Firefox from terminal using at command使用 at 命令从终端自动启动 Firefox
【发布时间】:2014-03-11 11:14:42
【问题描述】:

我是 linux 的初学者,并且非常热衷于学习操作系统。我正在尝试从命令行启动 Firefox(或任何其他软件,如 Evince),如下所示:

[root@localhost ~]# at 1637
[root@localhost ~]# at> firefox
[root@localhost ~]# at> ^d

作业被安排,没有任何错误。但是在指定的时间它没有运行。 我也尝试给出以下路径:

[root@localhost ~]# at 1637
[root@localhost ~]# at> /usr/bin/firefox
[root@localhost ~]# at> ^d

还是没有结果。但是当我尝试使用 echo 在屏幕上显示文本时,它会根据需要在指定时间出现。可能是什么问题?

【问题讨论】:

    标签: linux terminal scheduled-tasks at-job


    【解决方案1】:

    我认为你没有设置 DISPLAY。 at 将在未设置显示的单独 shell 中运行。 试试下面的代码。

    dinesh:~$ at 2120
    warning: commands will be executed using /bin/sh
    at>  export DISPLAY=:0
    at> /usr/bin/firefox > firefox.log 2>&1
    at> <EOT>
    job 7 at Tue Mar 11 21:20:00 2014
    

    如果仍然失败,请查看firefox.log 了解更多信息。

    【讨论】:

    • 我会试试这个。在哪里可以找到有关设置 DISPLAY 的更多信息?
    • 你可以找到更多信息HERE
    【解决方案2】:

    1) 并不总是建议以 root 身份运行东西

    2) 如果你在firefox的当前目录下,也可以试试./firefox。在 linux 中,您需要注意路径变量。除非.(当前目录)在您的路径中,否则如果程序与您在同一目录中,则必须键入./program

    您还需要注意文件权限:在 linux 中,您具有 read-write-eXecute 访问权限。

    ls -l 将列出目录并显示文件权限:

    drwxr-xr-x   10 user  staff     340 Oct  6  2012 GlassFish_Server/
    drwx------@  15 jeffstein  staff     510 Oct  6 15:01 Google Drive/
    drwxr-xr-x   20 jeffstein  staff     680 May 14  2013 Kindle/
    drwx------+  67 jeffstein  staff    2278 Jan 26 14:22 Library/
    drwx------+  19 jeffstein  staff     646 Oct 23 18:28 Movies/
    drwx------+  15 jeffstein  staff     510 Jan  3 20:29 Music/
    drwx------+  90 jeffstein  staff    3060 Mar  9 20:23 Pictures/
    drwxr-xr-x+   6 jeffstein  staff     204 Nov  3 21:16 Public/
    drwxr-xr-x   22 jeffstein  staff     748 Jan 14  2012 androidTools/
    -rwxrwxrwx    1 jeffstein  staff    1419 Aug 28  2013 color.sh*
    

    这是ls -l 的示例,您可以在这里看到 color.sh 有 -rwxrwxrwx,这意味着任何人都可以读取或写入或运行该文件。

    实际上不知道您在哪里安装了 firefox,但我无法提供更多帮助,但这些是一些可能会有所帮助的小提示。

    【讨论】:

    • 我已将 linux 安装为 VM,因此我以 root 身份运行它以避免文件权限问题。所以你的意思是说除非我指定路径,否则我不能运行任何软件?
    • 如果在 /usr/bin/firefox 中安装了 firefox,您可以更改为 /usr/bin 并输入 ./firefox,或者您可以输入 /usr/bin/firefox 并且它应该会运行。
    • 这样我就可以启动它了。如果您可以帮助我了解如何使用 {at} 命令安排在指定时间发生这种情况,那将非常有帮助。我在我的根帐户中收到一封邮件,上面写着“无法打开显示”。
    • 你看过 crontab 吗?
    • 是的,我做到了。它似乎正在处理这个问题。但我真的很想正确掌握所有概念,所以努力用 at 得到结果
    【解决方案3】:

    尝试使用“whereis firefox”命令查找实际安装 firefox 的位置。 然后尝试在 at 命令中使用该路径。

    【讨论】:

    • 谢谢。将尝试并重新发布。
    【解决方案4】:

    为了获得有关如何使用命令类型的说明:

    man at

    这将显示“手册”

    DESCRIPTION
         The at and batch utilities read commands from standard input or a speci-
         fied file.  The commands are executed at a later time, using sh(1).
    
         at      executes commands at a specified time;
    
         atq     lists the user's pending jobs, unless the user is the superuser;
                 in that case, everybody's jobs are listed;
    
         atrm    deletes jobs;
    
         batch   executes commands when system load levels permit; in other words,
                 when the load average drops below _LOADAVG_MX (1.5), or the value
                 specified in the invocation of at run.
    

    所以很明显你需要用at安排一个工作,你可以看看它是否和atq一起工作

    阅读手册,它应该会有所帮助 - 如果我有更多时间,我会给你写一个简单的例子。

    【讨论】:

    • 我会使用 cron 并得到结果。
    猜你喜欢
    • 1970-01-01
    • 2014-04-03
    • 1970-01-01
    • 2018-08-18
    • 2020-12-03
    • 2016-10-06
    • 2017-10-17
    • 1970-01-01
    • 2019-05-01
    相关资源
    最近更新 更多