linux centos 设置开启执行脚本

1、背景

     在开发程序过程中,希望在开机执行某个脚本,脚本中放置我们想要的逻辑。此时需要按照以下步骤进行执行。

2、操作步骤

(1) 检查 是否存在 /etc/rc.d/rc.local 文件,这个文件中可以编写开机要执行的内容,它对应的软链接为 /etc/rc.local

(2) vi /etc/rc.local  可以在该脚本 中 添加  “sh hello.sh”   , hello.sh 内容为 “echo  hello”

(3) 保存以上内容之后 ,执行  chmod -x /etc/rc.local   授权执行

(4)  reboot 重启计算机,可以看到界面输出  hello,说明 hello.sh  在 开机的时候被执行了

 

 

 

 

 

参考:

https://jingyan.baidu.com/article/3065b3b6af9597becff8a4fa.html

posted @ 2021-07-04 00:23  夏之夜  阅读(227)  评论(0编辑  收藏  举报