1.编辑/etc/rc.d/下的rc.local文件
如果还没有给与rc.local文件可执行权限,则先执行命令赋予rc.local可执行权限
chmod +x /etc/rc.d/rc.local
2.然后编辑rc.local文件,以在/mnt/why文件夹下执行脚本为例:
#!/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
cd /mnt/why
./monitor.sh >> logfile.log 2>&1
3.如果未执行成功,查看logfile.log日志,如果未找到脚本中的某个命令,但在Xshell又可以执行的话,则在脚本中的命令前加上
source /etc/profile
例如:
#!/bin/bash
source /etc/profile
nohup java -jar test.jar &