1. vi /etc/rc.local 增加java环境变量,否则javahome未加载
touch /var/lock/subsys/local
export JAVA_HOME=/home/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JRE_HOME=$JAVA_HOME/jre
# 以特定用户执行
su abc -c “/bin/bash /home/abc/autoStartTomcat.sh”
- vi /home/abc/autoStartTomcat.sh
#!/bin/sh
echo “启动”;
cd /home/abc/apache-tomcat-7.0.94/bin;
./startup.sh;
echo “启动接口”;
cd /home/abc/apache-tomcat-8.5.43-Interface_3396/bin;
./startup.sh;
- 脚本中切换用户
su abc << EOF
Whoami
cd /home/
pwd
EOF
执行结果
abc
/home