쉘 스크립트의 예상치 못한 출력

쉘 스크립트의 예상치 못한 출력

다음 스크립트는 디렉터리가 존재하고 크기가 10000KB를 초과하는지 확인하고 파일을 보관하고 삭제합니다.

crontab을 사용하여 스크립트를 실행할 때 오류 코드 1이 발생하면 output.log에 Tracedir이 존재하지 않는다고 나와 있지만 실제로는 존재합니다.

또한 for 루프에서 디렉토리를 인쇄하려고 시도했는데, Tracedir 값이 올바르게 인쇄되었습니다.

#!/bin/bash


sts=$(date)

echo "Script started running at $sts" > output.log

lsnrdir=$ORACLE_BASE/diag/tnslsnr/$HOSTNAME/listener/alert/

thr=10000

for i in $(ps aux | grep ora_smon | grep -v grep | awk '{print $11}' | cut -c10-17)

do

a=$(echo "$i" | tr '[:upper:]' '[:lower:]')

tracedir=$ORACLE_BASE/diag/rdbms/$a/$i/trace/

if [ -d $tracedir ]; then

size="$(du -s --exclude=*.tar.gz $tracedir | awk '{print $1}')"

if [ "$size" -ge $thr ]; then

echo "The trace and alert log size in $i  is: $size KB" >> output.log

echo "Trace and alert log archive started in $i ...." >> output.log

tar -czf $tracedir/dbtrace.tar.gz $tracedir

status=$?

if [ $status -ne 0 ]; then

echo "The error code is---"$status >> output.log

fi

echo "Trace and alert log archive completed in $i" >> output.log

sleep 5

tail -n 100 $tracedir/alert_$i.log > $tracedir/$i.log
mv $tracedir/$i.log $tracedir/alert_$i.log


find $tracedir -name "*.trc" -delete
find $tracedir -name "*.trm" -delete


echo "Removed trace files and log files in $i" >> output.log

else

echo "Trace log size in $i is not greater than $thr KB" >> output.log

fi

else

echo "No trace directory exists in $i" >> output.log

fi

done

관련 정보