自定义shell脚本服务开机自启动

来源:互联网 发布:阿里巴巴商学院 知乎 编辑:程序博客网 时间:2024/06/04 21:07

需求:启动linux是需要添加自定义ip地址到eth0网卡

在/etc/rc.d/init.d目录下编辑auto_run文本:

#!/bin/bash

#add ip eth0
ip addr add 10.8.2.1/32 dev eth0


添加auto_run服务:  chkconfig --add auto_run

报错:

service auto_run does not support chkconfig

经过查证后才知需要添加两句代码:

#chkconfig: - 85 15
#description: nginx is a World Wide Web server. It is used to serve


修改后:

#!/bin/bash

#add ip eth0
#chkconfig: - 85 15
#description: nginx is a World Wide Web server. It is used to serve

ip addr add 10.8.2.1/32 dev eth0


添加auto_run:

 chkconfig --add auto_run

成功!

设置auto_run服务开机自启动:

chkconfig auto_run on

0 0
原创粉丝点击