博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

创造加了日期的前十名磁盘空间用户报告的脚本

Posted on 2016-09-09 17:53  moss_tan_jun  阅读(150)  评论(0编辑  收藏  举报

#!/bin/bash
#Big_User - find big disk space users in various direcotries
#Parameters for Script
#
CHECK_DIRECTORIES="/var/log /home" #direcotries to check
#
######################Main Script###########################
#
DATE=`date +%m%d%y`               #Date for report file
exec > space_file_$DATA.rpt
#
#
echo "Top Ten Disk Space Usage"   #Report header for whole report
echo "for $CHECK_DIRECTORIES Direcotries"
#
for DIR_CHECK in $CHECK_DIRECTORIES #loop to du directories
do
       echo ""
       echo "The $DID_CHECK Directory:" #Title header for each direcotry
#
#Create a listing of top ten disk space users
       du -S $DIR_CHECK 2>/dev/null|sort -rn|sed '{11,$D;=}'|sed 'N;s/\n/ /'|gawk '{printf $1":""\t" $2"\t" $3"\n"}'
#
done
exec > /tmp/test.txt