blob: a14bbe3d71941d58d8143f9206146bde0a6f2ba2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/bin/bash
# Get CPU average
getCPU=$[100-$(vmstat 1 2|tail -1|awk '{print $15}')]
# Grab the second line of the ouput produced by the command: free -g (displays output in Gb)
getMem=$(free -h | sed -n '2p')
getMemPct=$(free -g | sed -n '2p')
# Split the string in secondLine into an array
read -ra ADDR <<< "$getMem"
read -ra ADDRPct <<< "$getMemPct"
# Get the total RAM from arrays
totalRam="${ADDR[1]//[^0-9.0-9]/}"
totalRamPct="${ADDRPct[1]}"
# Get the used RAM from arrays
usedRam="${ADDR[2]//[^0-9.0-9]/}"
usedRamPct="${ADDRPct[2]}"
# Calculate and display the percentages
pct="$(($usedRamPct*100/$totalRamPct))"
usage="$usedRam/$totalRam"
#echo "cpu:$getCPU% | mem:$pct% ($usage""G)"
echo "Cpu:$getCPU% | Mem:$pct% |"
|