4 [ "$1" = "-n" ] && noverb
=1
6 # Read /proc/stat file (for first datapoint)
7 read cpu user nice system idle iowait irq softirq steal guest
< /proc
/stat
9 # compute active and total utilizations
10 cpu_active_prev
=$
((user
+system
+nice
+softirq
+steal
))
11 cpu_total_prev
=$
((user
+system
+nice
+softirq
+steal
+idle
+iowait
))
15 # Read /proc/stat file (for second datapoint)
16 read cpu user nice system idle iowait irq softirq steal guest
< /proc
/stat
18 # compute active and total utilizations
19 cpu_active_cur
=$
((user
+system
+nice
+softirq
+steal
))
20 cpu_total_cur
=$
((user
+system
+nice
+softirq
+steal
+idle
+iowait
))
21 # compute CPU utilization (%)
22 cpu_util
=$
(( 100 * (cpu_active_cur
- cpu_active_prev
) / (cpu_total_cur
- cpu_total_prev
) ))
25 printf "%s\n" "$cpu_util"
27 printf "Current CPU Utilization: %s\n" "$cpu_util"