A shell script that counts CPU memory hard disk usage

Source: Internet
Author: User
Tags disk usage

A shell script that counts CPU memory hard disk usage for everyone to learn reference

#!/bin/bash#this Script isUse fordescrible CPU hard memery utilizationtotal=0Idle=0system=0User=0 Nice=0Mem=0vmexec=/usr/bin/Vmstatwhich SAR>/dev/NULL 2>&1if[$?-ne0]then ver= ' Vmstat-v | Awk'{printf $ A}'' Nice=0Temp= ' Vmstat1 3|tail-1' User= ' echo $temp |awk'{printf ("%s\n", $13)}'' System= ' echo $temp |awk'{printf ("%s\n", $14)}'' Idle= ' echo $temp |awk'{printf ("%s\n", $ $)}'' Total= ' Echo|awk'{print (C1+C2)}'c1= $system c2=$user ' Fiecho"#CPU utilization#"Echo"Total CPUs are already use: $total"Echo"CPU User is already use: $user"Echo"CPU system is already use: $system"Echo"CPU Nice was already use: $nice"Echo"CPU Idle is already use: $idle"Echoroot_use=$ (DF-LH | awk'nr==2'| Awk'{print $}') Dev_use=$ (DF-LH | awk'nr==3'| Awk'{print $}') Dev_shm_use=$ (DF-LH | awk'nr==4'| Awk'{print $}') echo"#Hard utilization#"Echo"/is already use: $root _use"Echo"/dev is already use: $dev _use"Echo"/dev/shm is already use: $dev _shm_use"echomemery_used=$ (Free | awk'nr==2'| Awk'{print $}') Memery_all=$ (Free | awk'nr==2'| Awk'{print $}') Memery_percent=$ (Echo"scale=4, $memery _used/$memery _all"|BC) Percent_part1=$ (echo $memery _percent | cut-c2-3) Percent_part2=$ (echo $memery _percent | cut-c4-5) echo"#Memery utilization#"Echo"system Memery is already use: $percent _part1. $percent _part2%"swap_used=$ (Free | awk'nr==4'| Awk'{print $}') Swap_all=$ (Free | awk'nr==4'| Awk'{print $}') Swap_percent=$ (Echo"scale=4, $swap _used/$swap _all"|BC) Swap_part1=$ (echo $swap _percent | cut-c2-3) Swap_part2=$ (echo $swap _percent | cut-c4-5) echo"swap memery is already use: $swap _part1. $swap _part2%"Echo

A shell script that counts CPU memory hard disk usage

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.