Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #POSITIONAL=()
- FILE_PATH="$2"
- #echo ${FILE_PATH};
- while true
- do
- # Read /proc/stat file (for first datapoint)
- read cpu user nice system idle iowait irq softirq steal guest< /proc/stat
- # compute active and total utilizations
- cpu_active_prev=$((user+system+nice+softirq+steal))
- cpu_total_prev=$((user+system+nice+softirq+steal+idle+iowait))
- sleep 5
- # Read /proc/stat file (for second datapoint)
- read cpu user nice system idle iowait irq softirq steal guest< /proc/stat
- # compute active and total utilizations
- cpu_active_cur=$((user+system+nice+softirq+steal))
- cpu_total_cur=$((user+system+nice+softirq+steal+idle+iowait))
- # compute CPU utilization (%)
- cpu_util=$((100*( cpu_active_cur-cpu_active_prev ) / (cpu_total_cur-cpu_total_prev) ))
- #printf " Current CPU Utilization : %s\n" "$cpu_util"
- DATE=`date '+%Y-%m-%d %H:%M:%S'`
- echo "$DATE Current CPU Utilization : $cpu_util" >> ${FILE_PATH}
- done
- #exit 0
Advertisement
Add Comment
Please, Sign In to add comment