统计linux硬盘使用率脚本,统计CPU、内存、硬盘使用率的shell脚本(图文)

#!/bin/bash

#This script is use for describle CPU Hard Memery Utilization

#edit by www.jquerycn.cn

total=0

idle=0

system=0

user=0

nice=0

mem=0

vmexec=/usr/bin/vmstat

which sar > /dev/null 2>&1

if [ $? -ne 0 ]

then

ver=`vmstat -V | awk '{printf $3}'`

nice=0

temp=`vmstat 1 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",$15)}'`

total=`echo|awk '{print (c1+c2)}' c1=$system c2=$user`

fi

echo "#CPU Utilization#"

echo "Total CPU  is already use: $total"

echo "CPU user   is already use: $user"

echo "CPU system is already use: $system"

echo "CPU nice   is already use: $nice"

echo "CPU idle   is already use: $idle"

echo

root_use=$(df -lh | awk 'NR==2' | awk '{print $5}')

dev_use=$(df -lh | awk 'NR==3' | awk '{print $5}')

dev_shm_use=$(df -lh | awk 'NR==4' | awk '{print $5}')

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"

echo

memery_used=$(free | awk 'NR==2' | awk '{print $3}')

memery_all=$(free | awk 'NR==2' | awk '{print $2}')

memery_percent=$(echo "scale=4;$memery_used / $memery_all" | bc)

percent_part1=$(echo $memery_percent | cut -c 2-3)

percent_part2=$(echo $memery_percent | cut -c 4-5)

echo "#Memery Utilization#"

echo "system memery is already use: $percent_part1.$percent_part2%"

swap_used=$(free | awk 'NR==4' | awk '{print $3}')

swap_all=$(free | awk 'NR==4' | awk '{print $2}')

swap_percent=$(echo "scale=4;$swap_used / $swap_all" | bc)

swap_part1=$(echo $swap_percent | cut -c 2-3)

swap_part2=$(echo $swap_percent | cut -c 4-5)

echo "swap   memery is already use: $swap_part1.$swap_part2%"

echo

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值