Recording time using shell scripts

This white paper suitable for just getting started, easy to understand. Great God do not read. Haha. . .

When we use automated deployment jenkins, a button to complete the deployment. But many white should also know that what had been done under specific button operation.

Since this article is primarily concerned with shell scripts, jenkins part is simply a. Press the button jenkins building, probably operating procedures are: compiler package -> Send to a designated server -> execute a shell script.

We look at an example of a shell script.

APP_NAME=lbccrm.jar

P_ID=`ps -ef | grep java | grep $APP_NAME|awk '{print $2}'`;

echo "########$SERVICE_NAME process pid is:$P_ID########"
if [ "$P_ID" == "" ]; then
        echo "########$SERVICE_NAME process not exists or stop success########"
else
        echo "########begin kill $SERVICE_NAME process, pid is:$P_ID########"
    kill -9 $P_ID
fi

sleep 2
current_dir=$(cd `dirname $0`; pwd)
echo "########current_dir is:$current_dir########"
nohup /data/opt/jdk1.8.0_181/bin/java -jar $current_dir/$APP_NAME > $current_dir/lbccrmlog.file   2>&1 &
echo "########$APP_NAME is success########"

Then this script specifically have done anything at all. Some knowledge of code, even if the person never learned shell script should be able to read a half. Here I will simply look at it, it is actually very simple.

= APP_NAME lbccrm.jar defined variables
PS = `-ef P_ID | grep Java | grep APP_NAME $ | awk 'Print $ {2}' `; Get our application PID 
echo command is output text
IF [ "$ P_ID" == ""]; the then 
        echo "$ ######## SERVICE_NAME Process Not EXISTS ######## Success or STOP" 
the else 
        echo "####### Process the kill $ SERVICE_NAME #begin, pid iS: $ P_ID ######## " 
    the kill -9 $ P_ID 
fi
means that after killing the program found P_ID
= $ current_dir (cd `dirname $ 0`; pwd ) to get the current directory
nohup /data/opt/jdk1.8.0_181/bin/java -jar $ current_dir / $ APP_NAME> $ current_dir / lbccrmlog.file 2> & 1 & Restart procedure
 
 

 

Guess you like

Origin www.cnblogs.com/feiyangbahu/p/12486401.html