Linux/Unix shell指令碼監控磁碟可用空間

來源:互聯網
上載者:User

Linux/Unix shell指令碼監控磁碟可用空間  Linux下監控磁碟的空閑空間的shell指令碼,對於系統管理員或DBA來說,必不可少。下面是給出的一個監控磁碟空間空間shell指令碼的樣本,供大家參考。 1、監控磁碟的空閑空間shell指令碼[python] robin@SZDB:~/dba_scripts/custom/bin> more ck_fs_space.sh   #!/bin/bash  # ------------------------------------------------------------------------------+  #                  CHECK FILE SYSYTEM SPACE BY THRESHOLD                        |  #   Filename: ck_fs_space.sh                                                    |  #   Desc:                                                                       |  #       The script use to check file system space by threshold                  |  #       Once usage of the disk beyond the threshold, a mail alert will be sent. |     #       Deploy it by crontab. e.g. per 15 min                                   |    #   Usage:                                                                      |  #       ./ck_fs_space.sh <percent> </filesystem [/filesystem2]>                 |    #                                                                               |  #   Author : Robinson                                                           |   # ------------------------------------------------------------------------------+  #  # -------------------------------  #  Set environment here   # ------------------------------    if [ -f ~/.bash_profile ]; then      . ~/.bash_profile  fi    export host=`hostname`  export mail_dir=/users/robin/dba_scripts/sendEmail-v1.56  export mail_list='Robinson.cheng@12306.com'  export mail_fm='oracle@szdb.com'  tmpfile=/tmp/ck_fs_space.txt  alert=n    # --------------------------------  #  Check the parameter  # --------------------------------    max=$1    if [ ! ${2} ]; then      echo "No filesystems specified."      echo "Usage: ck_fs_space.sh 90 / /u01"      exit 1  fi    # --------------------------------  #  Start to check the disk space  # --------------------------------    while [ "${2}" ]      do          percent=`df -P ${2} | tail -1 | awk '{print $5 }' | cut -d'%' -f1`          if [ "${percent}" -ge "${max}" ]; then              alert=y              break          fi;          shift      done;    # ------------------------------------------------------------------------  #  When a partition was above the threshold then send mail with df output  # ------------------------------------------------------------------------    if [ ! "${alert}" = 'n' ];then      df -h >$tmpfile      mail_sub="Disk usage beyond the threshold ${max} on ${host}."      $mail_dir/sendEmail -u ${mail_sub} -f $mail_fm -t $mail_list -o message-file=${tmpfile}  fi;    exit;  2、指令碼說明   a、該指令碼使用了 sendEmail 工具來發送郵件。   b、使用方式為"Usage: ck_fs_space.sh 90 / /u01" 。   c、指令碼中使用了一個while迴圈來逐個判斷所有的指定分區的空閑空間是否超出闕值。   d、對於超出闕值的情形發送郵件並且附上當前伺服器上磁碟空間的使用方式。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.