linux脚本开机启动配置(debian9)

1.建立一个sh文件

tee /etc/init.d/test <<EOF
#!/bin/bash
#Java环境变量 需要加入(没有java不用加)
添加命令
EOF

建好后赋予可执行权限 chmod +x test

2. 配置开机启动

方法一.创建rc.local (有的话不用建)

tee /etc/rc.lcoal <<EOF
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#添加sh文件
/etc/init.d/test
exit 0
EOF

赋予执行权限 chmod + /etc/rc.locale

方法二. 设置脚本开机时启动 (建议用方法一)

update-rc.d test defaults

设置脚本开机时不启动[可选]

update-rc.d -f test remove

3. 重启测试运行是否开机启动

分享你的喜爱