如何在启动时使用crontab运行bash脚本?其他解决方案尚未工作

发布于 2025-02-04 20:00:28 字数 444 浏览 2 评论 0原文

当我的机器使用Crontab启动时,我正在尝试运行一个bash脚本,该机器将打开终端,然后在该终端打开命令行工具BTOP。我编写的bash脚本在一个名为startm的文件中,内容如下:

#!/bin/bash
    gnome-terminal --command="bash -c 'btop; $SHELL'"

它打开终端,然后在该终端中运行BTOP命令。 $ shell位只是为了在脚本完成时保持终端窗口打开。

在我的crontab作为超级用户的crontab中,我输入以下内容:

@reboot /home/username/Scripts/startm

脚本已经可执行。如果有人对我做错了什么或可以实现这一目标的其他方法有任何想法,请回应。我是Linux&狂欢和任何指导将不胜感激。

I'm trying run a bash script when my machine boots up using crontab that will open a terminal and then open btop, a command-line tool, in that terminal. The bash script I've written is in a file named startm and the contents are below:

#!/bin/bash
    gnome-terminal --command="bash -c 'btop; $SHELL'"

It opens a terminal, then runs the btop command in that terminal. The $SHELL bit is just to keep the terminal window open when the script has finished running.

In my crontab as a superuser I input the following:

@reboot /home/username/Scripts/startm

The script is already executable. If anyone has any ideas about what I'm doing wrong, or other ways I can accomplish this, please respond. I am new to Linux & Bash and any guidance will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

软甜啾 2025-02-11 20:00:28

基本上,问题在于,您要在有GNOME桌面上运行它之前运行Gnome-ensinal,并且在登录之前不会有桌面。

一种方法是在登录时将某些内容放入您的〜/.bash-login脚本中或类似于运行脚本。

Basically, the problem is that you can't run gnome-terminal until there is a gnome desktop to run it on, and there won't be a desktop until you have logged in. Doing it from crontab is not going to work.

One way to do this is to put something into your ~/.bash-login script or similar to run the script when you login.

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