OS/Linux

쉘스크립트 조건부 실행

아르비스 2022. 6. 2. 09:14

shell Script로 linux에서 조건부 실행하는 부분 예제

#!/bin/bash
#RUN=`kubectl port-forward service/myrabbitmq --address 0.0.0.0 15672:15672`

#VALUE=`ps -ef | grep port-forward | grep -v "grep" | grep "15672" | awk '{print$2}'`
# awk '{print$2}' == PID

while true :
do
        VALUE=`ps -ef | grep port-forward | grep -v "grep" | grep "15672" | awk '{print$2}'`
        if [ -n $VALUE ]  # String null check
        then
                echo "PID = $VALUE"
                sleep 3600
        else
                echo "Not Exist : PID = $VALUE"
                #kubectl port-forward service/myrabbitmq --address 0.0.0.0 15672:15672
                sleep 5
        fi
        kubectl port-forward service/myrabbitmq --address 0.0.0.0 15672:15672 &
done