log_bak.sh 代码
bin_home=”/home//bin”
Folder_DEPLOY=$bin_home”/log”
log_back=”/home/logback”
function checkDerectory() {
if [ “ls -A $Folder_DEPLOY
” = “” ]; then
#do something
echo false
else
#do something
echo true
fi
}
function checkFiles() {
if [ “ls -A $Folder_DEPLOY
” = “” ]; then
#do something
echo false
else
#do something
echo true
fi
}
dates= (date−d“2daysago”+files=”log.” dates”*”
cd $bin_home
if [ -f
files];thenmv
files
FolderDEPLOYderecResult=
(checkDerectory)
#echo
derecResultif
derecResult ; then
#do something
#echo “now tar …”
cd
FolderDEPLOYtarfilename=”converter.log.”
dates”.tar.gz”
tar -czvf tarfilename *
#echo “now mv …”
mvtarfilename log_back
#echo “rm -rf …”
rm -rffiles
fi
fi
添加任务计划
查看任务计划
crontab -l
添加任务计划
crontab -e
10 0 * * * /home/bin/log_bak.sh
重启crontab
su root
service crond restart