使用shell 脚本进行系统管理

来源:互联网 发布:b2b网络平台有哪些 编辑:程序博客网 时间:2024/05/09 15:49

  该脚本用来发现磁盘上使用量比较大的目录

  摘自<linux 命令行与shell脚本编程大全>

#!/bin/bash##big_user - find big disk space users in various directories#########################################Parameters for script#CHECK_DIRECTORIES="/var/log /home / /usr/bin"   #directories to check###################################################  Main  Script  #####################ROOT_ID=0if [ $UID -ne $ROOT_ID ];then    echo " You have 'NO' rights to execute this script. Need root privilege"exit 1fiDATE=$(date '+%m%d%y')#exec > disk_space_$DATE.rptecho "Top Ten Disk Space Usage"echo " for $CHECK_DIRECTORIES"for dir_check in $CHECK_DIRECTORIESdoecho ""echo "The $dir_check Directory:"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


0 0
原创粉丝点击