有个脚本需要开机启动,结果 rc.local 老兄非常不给面子,折腾的心力交瘁死活就是不执行.
网上查了很多资料:
/etc/rc.d/rc.local 有执行权限
source /etc/profile 载入环境变量都没有解决问题
但我考虑肯定还是环境变量有问题, ssh 登上来就能执行,咋 rc.local 就不行呢!!!
于是,绝顶聪明的本人想出了一个绝顶聪明的办法... 通过 su -c 自动带入环境变量...
OK, reboot 脚本终于开机启动了 (๑•ᴗ•๑)
#!/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.
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
su -c /home/app/search/start.pl #就是这一行(๑•ᴗ•๑)
touch /var/lock/subsys/local