#!/bin/sh
HOSTNAME=`hostname -s`
echo "==============hostname================"
echo "hostname=$HOSTNAME"
MEMORYLINE=`free | grep Mem`
#字符串转数组
MEMORYARR=($MEMORYLINE)
echo "==============memory=================="
total=${MEMORYARR[1]}
used=${MEMORYARR[2]}
echo "total = $total"
echo "used = $used"
#计算百分比
used_pre=`echo "scale=2;$used*100/$total" | bc`
echo "used_pre = $used_pre"%
free=${MEMORYARR[3]}
echo "free = $free"
free_pre=`echo "scale=2;$free*100/$total" | bc`
echo "free_pre = $free_pre"%
echo "================CPU==================="
原文地址:https://www.cnblogs.com/cation/p/8630556.html
时间: 2024-11-07 01:07:43