안녕하세요. while 루프를 사용하여 다른 스크립트를 호출하는 스크립트가 있는데, 각 루프에 걸리는 시간을 계산하는 방법을 알아야 합니다. 예를 들면 다음과 같습니다.
Starting NodeManager...
NodeManager Started
Elapsed time: 00:00:10
Starting AdminServer...
AdminServer Started
Elapsed time: 00:01:10
이게 스크립트야
#!/bin/bash
set -e
clear
TFILE=starting.log
#--------------------------------------------------------------------------------
Check_Status_NM ()
{
tail -F ${TFILE} | while read LOGLINE
do
if [[ "${LOGLINE}" == *"Secure socket listener started on port"* ]]
then
pkill -P $$ tail
break
elif [[ "${LOGLINE}" == *"Address already in use"* ]]; then
pkill -P $$ tail
echo -e "Cannot Start Server\nSee starting.log for more info "
exit 1
fi
done
}
#----------------------------------------------------------------
Check_Status ()
{
tail -F ${TFILE} | while read LOGLINE
do
if [[ "${LOGLINE}" == *"The Network Adapter could not establish the connection"* ]] ; then
echo -e "\e[5m\e[93mWARNING\e[0m Could not establish the connection\n\e[91mCheck Connection to Database\e[0m\n"
elif [[ "${LOGLINE}" == *"<Server started in RUNNING mode>"* ]]
then
pkill -P $$ tail && cat /dev/null > ${TFILE}
sleep 1
break
elif [[ "${LOGLINE}" == *"<Server state changed to FORCE_SHUTTING_DOWN>"* ]] || [[ "${LOGLINE}" == *"Address already in use"* ]]; then
pkill -P $$ tail
echo -e "\e[91mCannot Start Server\e[0m\nSee starting.log for more info "
exit 1
fi
done
}
export JAVA_OPTIONS="-Dweblogic.management.username=weblogic -Dweblogic.management.password=oracle11g"
#-------Start NodeManager-------------------------------------------------------
echo -e "Starting NodeManager..."
nohup "$WLS_HOME"/server/bin/startNodeManager.sh > ${TFILE} 2>&1 &
Check_Status_NM
echo -e "NodeManager \e[92mStarted\e[0m\n"
#--------------------------Start WebLogic Domain------------------------------------------------
echo -e "Starting AdminServer..."
nohup "$DOMAIN_HOME"/bin/setDomainEnv.sh > ${TFILE} 2>&1 &
nohup "$DOMAIN_HOME"/bin/startWebLogic.sh > ${TFILE} 2>&1 &
Check_Status
echo -e "AdminServer \e[92mStarted\e[0m\n"
#----------- Start FORMS------------------------------
echo "Starting Forms Server..."
nohup "$DOMAIN_HOME"/bin/startManagedWebLogic.sh WLS_FORMS t3://$(hostname):7001 > ${TFILE} 2>&1 &
Check_Status
echo "Forms Server \e[92mStarted\e[0m\n"
#----------- Start Reports------------------------------
echo -e "Starting Reports Server..."
nohup "$DOMAIN_HOME"/bin/startManagedWebLogic.sh WLS_REPORTS t3://$(hostname):7001 > ${TFILE} 2>&1 &
Check_Status
echo -e "Reports Server \e[92mStarted\e[0m\n"
#---------------------Start anything remaining using OPMN------------------------
opmnctl startall ; opmnctl status ; emctl start agent
답변1
Bash에는 "타이머"가 내장되어 있습니다. 타이밍을 시작하려면 변수를 SECONDS
0(영)으로 설정하고 해당 값을 읽어 마지막 재설정 이후 경과된 시간(초)을 가져옵니다.