From cbdd4be84fb97b3d35f6d21b9bfbd8b4c339f0ec Mon Sep 17 00:00:00 2001 From: wxy Date: Sun, 10 Dec 2017 09:15:42 +0800 Subject: [PATCH] PRF&PUB:20170918 Executing Commands and Scripts at Reboot & Startup in Linux.md @lujun9972 https://linux.cn/article-9123-1.html --- ...nd Scripts at Reboot & Startup in Linux.md | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) rename {translated/tech => published}/20170918 Executing Commands and Scripts at Reboot & Startup in Linux.md (77%) diff --git a/translated/tech/20170918 Executing Commands and Scripts at Reboot & Startup in Linux.md b/published/20170918 Executing Commands and Scripts at Reboot & Startup in Linux.md similarity index 77% rename from translated/tech/20170918 Executing Commands and Scripts at Reboot & Startup in Linux.md rename to published/20170918 Executing Commands and Scripts at Reboot & Startup in Linux.md index 107caa6bd9..cc308d7554 100644 --- a/translated/tech/20170918 Executing Commands and Scripts at Reboot & Startup in Linux.md +++ b/published/20170918 Executing Commands and Scripts at Reboot & Startup in Linux.md @@ -1,39 +1,39 @@ 在 Linux 启动或重启时执行命令与脚本 ====== + 有时可能会需要在重启时或者每次系统启动时运行某些命令或者脚本。我们要怎样做呢?本文中我们就对此进行讨论。 我们会用两种方法来描述如何在 CentOS/RHEL 以及 Ubuntu 系统上做到重启或者系统启动时执行命令和脚本。 两种方法都通过了测试。 ### 方法 1 – 使用 rc.local -这种方法会利用 `/etc/` 中的 `rc.local` 文件来在启动时执行脚本与命令。我们在文件中加上一行 l 爱执行脚本,这样每次启动系统时,都会执行该脚本。 +这种方法会利用 `/etc/` 中的 `rc.local` 文件来在启动时执行脚本与命令。我们在文件中加上一行来执行脚本,这样每次启动系统时,都会执行该脚本。 不过我们首先需要为 `/etc/rc.local` 添加执行权限, -```shell +``` $ sudo chmod +x /etc/rc.local ``` -然后将要执行的脚本加入其中, +然后将要执行的脚本加入其中: -```shell +``` $ sudo vi /etc/rc.local ``` -在文件最后加上 +在文件最后加上: -```shell +``` sh /root/script.sh & ``` -然后保存文件并退出。 -使用 `rc.local` 文件来执行命令也是一样的,但是一定要记得填写命令的完整路径。 像知道命令的完整路径可以运行 +然后保存文件并退出。使用 `rc.local` 文件来执行命令也是一样的,但是一定要记得填写命令的完整路径。 想知道命令的完整路径可以运行: -```shell +``` $ which command ``` -比如, +比如: -```shell +``` $ which shutter /usr/bin/shutter ``` @@ -48,13 +48,13 @@ $ which shutter 要创建 cron 任务,打开终端并执行 -```shell +``` $ crontab -e ``` 然后输入下行内容, -```shell +``` @reboot ( sleep 90 ; sh \location\script.sh ) ``` @@ -68,7 +68,7 @@ via: http://linuxtechlab.com/executing-commands-scripts-at-reboot/ 作者:[Shusain][a] 译者:[lujun9972](https://github.com/lujun9972) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出