菜鸟写的清理文件的shell脚本

#!/bin/sh

ema_file_path="/home/sqlback/enigma"
cng6_file_path="/home/sqlback/cng/cng_6"
cng7_file_path="/home/sqlback/cng/cng_7"
log_file_path="/home/sqlback/logs"
time=$(date "+%Y-%m-%d")
log_name="${log_file_path}/${time}_clear_file.log"

echo "" >> ${log_name}
echo "clear file" >> ${log_name}
echo "" >> ${log_name}

function clearFile()
{
    i=$1
    while((i > 6 ))
        do
		#into file path
		cd $2
		
		#get the oldest file's name 
		oldest_file=$((ls -l *.sql || ls -l *.log)|head -1|awk '{print $9}')
		
		echo "the oldest file is: ${oldest_file}" >> ${log_name}
		rm -f ${oldest_file}

		let i=i-1
	done
}

echo "clear enigma file..." >> ${log_name}
cd ${ema_file_path}
ema_file_num=$(ls -l|grep "^-"|wc -l)
clearFile ${ema_file_num} ${ema_file_path}
echo "enigma file clear end" >> ${log_name}
echo "" >> ${log_name}

echo "clear cng_6 file..." >> ${log_name}
cd ${cng6_file_path}
cng6_file_num=$(ls -l|grep "^-"|wc -l)
clearFile ${cng6_file_num} ${cng6_file_path}
echo "cng6 file clear end" >> ${log_name}
echo "" >> ${log_name}

echo "clear cng_7 file..." >> ${log_name}
cd ${cng7_file_path}
cng7_file_num=$(ls -l|grep "^-"|wc -l)
clearFile ${cng7_file_num} ${cng7_file_path}
echo "cng7 file clear end" >> ${log_name}
echo "" >> ${log_name}

echo "clear log file..." >> ${log_name}
cd ${log_file_path}
log_file_num=$(ls -l|grep "^-"|wc -l)
clearFile ${log_file_num} ${log_file_path}
echo "log file clear end" >> ${log_name}
echo "" >> ${log_name}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值