【发布时间】:2025-06-09 00:40:01
【问题描述】:
我有一个脚本文件,每次 ubuntu 启动时我都需要运行它,所以我怎样才能把那个文件放在启动时。不在每次都会运行的启动文件夹中,但我需要找到其他方式来每次运行该脚本我该怎么做?
我已经使用了一些参考,但它不起作用。 How to run a script at the start up of Ubuntu?
【问题讨论】:
标签: shell ubuntu registerstartupscript
我有一个脚本文件,每次 ubuntu 启动时我都需要运行它,所以我怎样才能把那个文件放在启动时。不在每次都会运行的启动文件夹中,但我需要找到其他方式来每次运行该脚本我该怎么做?
我已经使用了一些参考,但它不起作用。 How to run a script at the start up of Ubuntu?
【问题讨论】:
标签: shell ubuntu registerstartupscript
运行以下命令创建新的 cronjob 条目
$ crontab -e
它将打开文本编辑器。(第一次它会要求您选择默认文本编辑器)。使用 @reboot 关键字添加脚本
@reboot /path/to/your/script.sh
保存文件。就是这样。
【讨论】:
nano,最简单。
test.sh 位于 /home/krishna/scripts/ 目录中,然后将 @reboot /home/krishna/scripts/test.sh 添加到您的 cronjob 编辑器中。