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