使用最简单的方式
首先创建一个shell脚本,比如命名为test.sh,路径为path
然后打开/etc/rc.local
在最后(在exit 0(ubuntu系统))添加加shell脚本路径
如果想不中断的在后台运行的话代码如下
nohup shell脚本路径 &
示例
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
nohup /etc/init.d/nmon.sh &
最后赋予权限
sudo chmod +x /etc/rc.local