出于某种原因,我在运行脚本时没有得到第二条回音线的输出。这是我的代码片段:
IS_RUNNING=$(netstat -anp | grep ":7600" | grep java | awk '{print $7}' | cut -d"/" -f 2)
start(){
nohup /bin/su -c "/opt/app/bin/service start" - user &>/dev/null &
echo "Starting Services please wait"
sleep 30
if [ "$IS_RUNNING" = java ];
then
echo "Service is now running"
exit 0
fi
}
有趣。当我用它运行时:
sh -x ./service start
我得到预期的输出,我的第二个回声被写入屏幕。
+ case "$1" in
+ start
+ echo 'Starting Services please wait'
Starting Services please wait
+ sleep 30
+ nohup /bin/su -c '/opt/app/bin/service start' - user
+ '[' java = java ']'
+ echo 'Service is now running'
Service is now running
+ exit 0
不使用sh -x,我只是得到这个:
[root@init.d]# ./service start
Starting Services please wait
[root@init.d]#
我有一种感觉,我忽略了一些简单的事情。有人可以帮忙吗?
答案 0 :(得分:2)
对运行线进行一次评估:
IS_RUNNING=$(netstat -anp | grep ":7600" | grep java | awk '{print $7}' | cut -d"/" -f 2)
你应该为此创建一个函数,或者在sleep()之后在start()函数中包含这一行。