#!/bin/bash
#说明: 检测设备上大于50M的文件
#脚本名称:check_disk_space.sh
#执行思路:
#********************************下面是所有函数以及作用到列表*****************************************
file_gt_50M=50000 #检测设备上大于50M的文件,这个值可以调整
big_file_list="/fwlog/big_file_list"
#函数功能:获取所有的分区
#参数:
#返回值:返回物理分区的目录
get_all_partition(){
local all_partition=`df -h | awk '{if ($1~/dev\/sd/) {print $6}}'`
echo $all_partition;
}
get_big_file(){
all_big_files=`du -a $1 | sort -rn | head -n 200 | awk -v file_size="$file_gt_50M" '{if ($1 > file_size){print $2}}'`
for one_file in $all_big_files
do
#if [[ ! -d $one_file && -f $one_file ]]
if [ -f "$one_file" ]; then
{
one_size=`ls -alh $one_file | awk '{print $5}'`
#echo -e "$one_file \t\t\t\t\t\t\t\t\t\t\t $one_size" | tee -a $big_file_list
printf "%-80s" $one_file | tee -a $big_file_list
printf "%s\n" $one_size | tee -a $big_file_list
}
fi
done
}
main_function()
{
local all_partition=`get_all_partition`
for one_partition in $all_partition
do
get_big_file $one_partition
done
}
#清空日志文件
echo > $big_file_list
echo "begin check big file,date: `date`" | tee -a $big_file_list
main_function
echo "end check big file,date: `date`" | tee -a $big_file_list