sh文件
#!/bin/sh
myPath="/var/www/Client/storage/logs/"
myFile="lumen.log"
cd $myPath
date=$(date +%Y%m%d)
find ${myPath} -type f -name "*.gz" -mtime +30 -exec rm {} \;
#這里的-f參數(shù)判斷$myFile是否存在
if [ -e "$myFile" ]; then
mv $myFile ${myFile%.*}${date}.${myFile##*.}
tar -zcvf ${myFile%.*}${date}.log.tar.gz ${myFile%.*}${date}.${myFile##*.}
rm -rf $myPath/${myFile%.*}${date}.${myFile##*.}
fi
只要定時任務(wù)中添加即可墓拜,注意 要是同時運行 ,多個腳本的壓縮命令请契。 不要在一個時間 進行 咳榜,會導(dǎo)致 壓縮失敗