fix _make_git_tar_dir.sh - don't 'append directory' to symlinks
[cmdllinux.git] / scripts / _cpu_usage
blob4c9a7a79ef269d056ee78d04406f66ec96c33a19
1 #!/bin/bash
2 # Found on WWW
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))
13 usleep 50000
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) ))
24 if [ $noverb ]; then
25 printf "%s\n" "$cpu_util"
26 else
27 printf "Current CPU Utilization: %s\n" "$cpu_util"
30 exit 0