脚本监测 前十名磁盘空间用户的列表

脚本名称为: Big_Users.sh 

#!/bin/bash
#
#  Big_Users - find big disk space users in various directories
################################################################
#  Parameters for Script
#
CHECK_DIRECTORIES=" /var/log /home" #directories to check
#
################# main Script ############################
#
DATE=$(date '+%m%d%y')       #Date for report file
#
exec > disk_space_$DATE.rpt    #Make report file Std Output
#
echo > "Top Ten Disk Space Usage"   #report header for whole report
echo "for $CHECK_DIRECTORIES Directories"
#
for DIR_CHECK in $CHECK_DIRECTORIES    #loop do du directories
do 
  echo ""
  echo "The $DIR_CHECK Directory:"  #Title header for each directory
#
# 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               #end of dor loop for du directories
#

监测的目录为:  /var/log /home 

利用

 sed '{11,$D;=}' |
 sed 'N; s/\n/ /' |
 gawk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'

来选择前十个磁盘空间;排列的数字与十个空间列表并列;打印出结果

最后的结果会存进 disk_space_$DATE.rpt 的文件

最后在利用cron,在每周一早晨7:15执行该脚本文件

15 7 * * 1 /home/user/Big_Users.sh

cron为Linux系统下设置定时任务

详见 -> 戳我

posted @ 2015-09-12 19:58  todaytoday  阅读(255)  评论(0编辑  收藏  举报