Press "Enter" to skip to content

[일:] 2024년 01월 08일

배치 실행 로그 파일로 기록 및 30일 초과시 자동 삭제

!/bin/sh

# 현제 날짜
today=$(date "+%Y%m%d")

# 로그 남기는 형태로 변경
logfile=/home/path/txt/${today}log.txt
sudo sh -c "sudo php log_print.php" >> ${logfile}

# 로그파일 30일 이전 삭제
delfile=`date --date="$GIVEN_DAY" -d "-30 day" +%Y%m%d`
#echo $delfile

dellogfile=/home/path/txt/${delfile}log.log
#echo $dellogfile
if [ -f $dellogfile ]; then
    rm $dellogfile
#    echo "file exist"
fi