CentOS系统设置开机自动运行脚本

/etc/rc.d/rc.local 文件会在 Linux 系统各项服务都启动完毕之后再被运行。所以你想要自己的脚本在开机后被运行的话,可以将自己脚本路径加到该文件里。

首先先给 rc.local 文件添加权限

$ chmod +x /etc/rc.d/rc.local

创建一个脚本,用于系统启动后运行。

## 开机时将当前时间写入 text.md 文件中
$ cd /home
$ touch auto_run_script.sh
$ chmod +x auto_run_script.sh
$ echo "date >> text.md" >> auto_run_script.sh

$ touch text.md

然后将我们的脚本添加到 /etc/rc.d/rc.local 文件中。

$ cd /etc/ec.d
$ echo /home/auto_run_script.sh >> ec.local

这样就可以了,我们重启系统后就可以看到当前的日期写入到 text.md 文件中了。

posted @ 2020-06-22 15:35  LiuChengloong  阅读(716)  评论(0编辑  收藏  举报