linux磁碟空間警示指令碼

來源:互聯網
上載者:User

標籤:linux   磁碟   指令碼   警示   

1.必須函數:

[[email protected] ~]# df

檔案系統               1K-塊        已用     可用 已用% 掛載點

/dev/mapper/VolGroup00-LogVol00

                      11109328   2154636   8381252  21% /

/dev/sda1               101086     11999     83868  13% /boot

tmpfs                  1037748         0   1037748   0% /dev/shm

[[email protected] ~]# df | sed -n ‘/\/$/p‘

                      11109328   2154636   8381252  21% /

/$:表示以斜杠(/)結尾($)的行

[[email protected] ~]# df | sed -n ‘/\/$/p‘ | gawk ‘{print $4}‘

21%

$4:表示列印出第四個欄位


[[email protected] ~]# df | sed -n ‘/\/$/p‘ | gawk ‘{print $4}‘|sed ‘s/%//‘

21

s:替換

s/%//:表示將百分比符號替換成空


2.建立指令碼

建立一個指令碼,提示當/的使用空間超過10%的時候,向ley的使用者發送一封警示郵件

#!/bin/bash

#monitor available disk space

s=`df | sed -n ‘/\/$/p‘ | gawk ‘{print $4}‘|sed ‘s/%//‘`

if [ $s -ge 10 ]

   then

echo "$s% userd" | mail -s "Disk warning" ley

fi

~    

ley使用者必須是在系統中存在的使用者

******************************************************************************************

[[email protected] ~]$ mail  查看郵件

Mail version 8.1 6/6/93.  Type ? for help.

"/var/spool/mail/ley": 5 messages 5 new

>N  1 [email protected]  Wed Nov  5 17:02  16/654   "Disk warning"

 N  2 [email protected]  Wed Nov  5 17:02  16/654   "Disk warning"

 N  3 [email protected]  Wed Nov  5 17:04  16/654   "Disk warning"

 N  4 [email protected]  Wed Nov  5 17:04  16/654   "Disk warning"

 N  5 [email protected]  Wed Nov  5 17:04  16/654   "Disk warning"

Message 1:  第一條資訊

From [email protected]  Wed Nov  5 17:02:16 2014

Date: Wed, 5 Nov 2014 17:02:16 +0800

From: root <[email protected]>

To: [email protected]

Subject: Disk warning


21% userd


本文出自 “linux營運分享” 部落格,請務必保留此出處http://liangey.blog.51cto.com/9097868/1572228

linux磁碟空間警示指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.