#!/bin/bash
##################
. /etc/profile
. ~/.bash_profile
##################
i=0
k=0
echo "`date +%Y%m%d%H%M`" > /tmp/size0.log
# 定义一个方法
foreachd(){
# 遍历参数1
for file in $1/*
do
# 如果是文件就打印处理,然后继续遍历,递归调用
if [ -d $file ]
then
# echo $file
foreachd $file
else
filesize=`ls -l $file | awk '{print $5}' `
if [ "$filesize" = "0" ];then
echo "$file size is 0" >> /tmp/size0.log
a[$k]="$file"
k=`expr $k + 1`
fi
i=`expr $i + 1`
echo "$file size is $filesize"
fi
done
}
weberror(){
if [ "${#a[*]}" -eq "0" ];then
echo "所有文件size均大于0"
exit 0
else
echo "总共检测 ${#a[*]}个size大小为0文件"
for ((j=0; j<=`expr "${#a[*]}" - 1`;j++)) ;do
# echo "${a[0]}"
echo "`date +%Y%m%d%H%M%S` ${a[$j]}"
# echo "`date +%Y%m%d%H%M$S` ${a[$j]}" | mail -s "`date +%Y%m%d%H%M$S` ${a[$j]}" $notice_mail
done
# time2=`date +%Y%m%d%H%M%S`
# echo "$time1 $time2"
exit 2
fi
}
#echo "总共有$i 个页面,其中size 为0的页面有`expr `more /tmp/size0 | wc -l` - 1`个"
# 执行,如果有参数就遍历指定的目录,否则遍历当前目录
#if ($0 > 0)
if [[ ! -z $1 ]];then
foreachd "$1"
weberror
# echo $#
# echo 1
echo "总共有$i 个页面,其中size 为0的页面有`more /tmp/size0.log | wc -l` - 2 个"
else
foreachd `/bin/pwd`
weberror
# pwd=`pwd`
# echo 2
# echo $#
# foreachd "./"
echo "总共有$i 个页面,其中size 为0的页面有 `more /tmp/size0.log | wc -l` - 2个"
fi
##################
. /etc/profile
. ~/.bash_profile
##################
i=0
k=0
echo "`date +%Y%m%d%H%M`" > /tmp/size0.log
# 定义一个方法
foreachd(){
# 遍历参数1
for file in $1/*
do
# 如果是文件就打印处理,然后继续遍历,递归调用
if [ -d $file ]
then
# echo $file
foreachd $file
else
filesize=`ls -l $file | awk '{print $5}' `
if [ "$filesize" = "0" ];then
echo "$file size is 0" >> /tmp/size0.log
a[$k]="$file"
k=`expr $k + 1`
fi
i=`expr $i + 1`
echo "$file size is $filesize"
fi
done
}
weberror(){
if [ "${#a[*]}" -eq "0" ];then
echo "所有文件size均大于0"
exit 0
else
echo "总共检测 ${#a[*]}个size大小为0文件"
for ((j=0; j<=`expr "${#a[*]}" - 1`;j++)) ;do
# echo "${a[0]}"
echo "`date +%Y%m%d%H%M%S` ${a[$j]}"
# echo "`date +%Y%m%d%H%M$S` ${a[$j]}" | mail -s "`date +%Y%m%d%H%M$S` ${a[$j]}" $notice_mail
done
# time2=`date +%Y%m%d%H%M%S`
# echo "$time1 $time2"
exit 2
fi
}
#echo "总共有$i 个页面,其中size 为0的页面有`expr `more /tmp/size0 | wc -l` - 1`个"
# 执行,如果有参数就遍历指定的目录,否则遍历当前目录
#if ($0 > 0)
if [[ ! -z $1 ]];then
foreachd "$1"
weberror
# echo $#
# echo 1
echo "总共有$i 个页面,其中size 为0的页面有`more /tmp/size0.log | wc -l` - 2 个"
else
foreachd `/bin/pwd`
weberror
# pwd=`pwd`
# echo 2
# echo $#
# foreachd "./"
echo "总共有$i 个页面,其中size 为0的页面有 `more /tmp/size0.log | wc -l` - 2个"
fi