I have following code that prints
- Disk Usage: 78/223GB (35%)
- CPU Load: 2.00
- Memory Usage: 5650/16302MB(34.66)
But I want to use out as variables in bah script insated of printing them. How can i do that ?
What I want:
#!/bin/sh
# I want 3 variables which have values from awk
# How can i convert awk command below to do that ?
$disk_usage
$CPU_usage
$Memory_usage
CODE:
awk 'BEGIN {
while("df -hP " | getline) {
if ( $NF == "/" ) {
printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5
}
}
while( getline < "/proc/loadavg" ) {
printf "CPU Load: %.2f\n", $(NF-2)
}
while( "free -m"| getline) {
if( $0 ~ /Mem:/) {
printf "Memory Usage: %s/%sMB (%.2f%)\n", $3,$2,$3*100/$2
}
}
}'