我正在编写一个修改一些配置文件的bash脚本,作为不同的用户运行“ant ear war”,输出返回,退出到root以继续执行其余的脚本。问题是脚本在退出后没有继续,我没有得到“蚂蚁耳朵战争”的输出。
感谢您的帮助。
这是一个例子
#When running the bash script i don't see the output. Maybe it's because I run it as root and switched to another_user. So I tried to outputing result into a variable and into a text file. Both failed
su another_user
cd /usr/empi/MMEMPIV741/
echo $(ant ear war) >> /tmp/empi_install.txt
varant="$?"
echo 'if zero it's success otherwise it's a failure'
cp /usr/accessmgr/AMV741/bin/am/JBoss/AccessManager.war /usr/jboss/jboss-eap-4.3/jboss-as/server/default/deploy/
cp /usr/empi/MMEMPIV741/person_project/working-dir/dist/* /usr/jboss/jboss-eap-4.3/jboss-as/server/default/deploy/
exit
#By this time above is exited from another_user and should return to root
echo $varant
echo "http://`hostname`:21080/PersonMasterIndexDQM/flex/login.jsp#"
答案 0 :(得分:3)
将要在其他用户上下文中运行的命令放入单独的脚本中,并通过
运行该脚本su another_user -c /path/to/other.sh