分类: 系统运维
2019-11-22 14:29:41
老脚本,分享一下,df -h发现使用率告警,找出占用空间的大文件的shell脚本。
#!/bin/ksh
#Authorname :wangt009
#Scriptname :pwdanalyse.sh
#Version :v1.0 20170825 #create
#Description:analyse pwd 's usage
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/python27/bin:/usr/local/bin/:/qhapp/sysinfo/bin:/qhapp/ump/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/lib/oracle/11.2/client64/bin:/root/bin:/qhapp/sysinfo/bin:/qhapp/ump/bin/
TIMESTAMP=`date +"%Y%m%d%H%M%S"`
TMPFILEA=/tmp/pwdanalyse.TMPFILEA.$TIMESTAMP
func_getpwdinfo(){
NUM=0
du -ak $PWDINFO|sort -nr>$TMPFILEA
cat $TMPFILEA|while read name
do
SIZE_K=`echo $name|awk '{print $1}'`
FILEINFO=`echo $name|awk '{print $2}'`
if [ -f $FILEINFO ]
then
NUM=`echo $NUM+1|bc`
SIZE_M=`echo $SIZE_K/1024|bc`
echo $NUM $SIZE_M"MB" $FILEINFO
if [ $NUM -eq $MAXFILENUM ]; then exit; fi
fi
done|awk '{printf"%-4d%-10s%-10s\n",$1,$2,$3}'
}
func_help(){
if [ "$1"x == '-hx' ]
then
echo "usage : pwdanalyse.sh [pwdinfo] [maxfilenum]"
echo "example : pwdanalyse.sh /tmp/ 10 #pwd is /tmp/ , max num of biggest files is 10."
echo "example : pwdanalyse.sh #default value.pwdinfo=/qhapp/,maxfilenum=20."
echo "example : pwdanalyse.sh -h #print help info. "
exit
fi
}
#################main#####################
if [ "$1" ]
then
func_help $1
PWDINFO=$1
else
#PWDINFO=/ebsapp
#PWDINFO=/opt
PWDINFO=/qhapp
fi
if [ ! "$2" ] ;then MAXFILENUM=20;else MAXFILENUM=$2;fi
func_getpwdinfo $PWDINFO $MAXFILENUM
rm $TMPFILEA
使用方法:
sz180001:root@/qhapp/ump/bin>pwdanalyse.sh -h
usage : pwdanalyse.sh [pwdinfo] [maxfilenum] example : pwdanalyse.sh /tmp/ 10 #pwd is /tmp/ , max num of biggest files is 10. example : pwdanalyse.sh #default value.pwdinfo=/qhapp/,maxfilenum=20. example : pwdanalyse.sh -h #print help info.