如何在启动时使用crontab运行bash脚本?其他解决方案尚未工作
当我的机器使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,问题在于,您要在有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.