Linux hard disk usage and Shell script implementation

Source: Internet
Author: User
Tags disk usage

Use df-tph to view hard disk usage under Linux:

sdua:/# Df-tphfilesystem                  Type   Size  used Avail use% mounted On/dev/vda3                   ext3   2.0G  974M  940M  51%/udev                        tmpfs   16G  500K   16G   1%/devtmpfs                       tmpfs   32G  9.4G   23G  30%/dev/shm/dev/vda2                   ext3  1008M   56M  902M   6%/boot/dev/vda9                   ext3    20G  173M   19G   1%/core/dev/vda8                   ext3    28G  2.5G   24G  10%/home/dev/vda10                  Ext3    21G  6.1G   14G  31%/opt/dev/vda6                   ext3   4.0G  186M  3.6G   5%/ Vartmpfs                       tmpfs  512M  620K  512M   1%/tmpshm                         tmpfs   32G  9.4G   23G  30%/dev/shm/dev/mapper/vgdb-lv_bakdata ext3    11G  326M  9.8G   4%/home/oracle/rmcbak/dev/mapper/ Vgdb-lvarchive  ext3    11G  156M  9.9G   2%/home/oracle/archive

Remove filesystem rows, Tmpfs rows (Tmpfs is a memory-based file system), obtaining the hard disk name and usage rate:

The actual shell script is implemented as follows:

#!/bin/bash# Set alert level 90% is defaultalert=50df-tph | Grep-ve ' ^filesystem|tmpfs|cdrom ' | awk ' {print $6 ' "$} ' |  While read Output;do   usep=$ (echo $output | awk ' {print $} ' | cut-d '% '-F 1)   partition=$ (echo $output | awk ' { Print $} ')   if [$usep-ge $ALERT]; then       echo "Running Out of space $partition ($usep%) on $ (date +%y-%m-%d)" C4/>fidoneexit 0

Running effect exceeds 50% usage rate:

  

Linux hard disk usage and Shell script implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.