SHARE
TWEET

Untitled

a guest May 19th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.     USER1=`cat /proc/stat | grep "cpu " |  awk '{print $2}'`
  3.     NICE1=`cat /proc/stat | grep "cpu " |  awk '{print $3}'`
  4.     SYSTEM1=`cat /proc/stat | grep "cpu " |  awk '{print $4}'`
  5.     IDLE1=`cat /proc/stat | grep "cpu " |  awk '{print $5}'`
  6.     IOWAIT1=`cat /proc/stat | grep "cpu " |  awk '{print $6}'`
  7.     IRQ1=`cat /proc/stat | grep "cpu " |  awk '{print $7}'`
  8.     SIRQ1=`cat /proc/stat | grep "cpu " |  awk '{print $8}'`
  9.     sleep 1
  10.     USER2=`cat /proc/stat | grep "cpu " |  awk '{print $2}'`
  11.     NICE2=`cat /proc/stat | grep "cpu " |  awk '{print $3}'`
  12.     SYSTEM2=`cat /proc/stat | grep "cpu " |  awk '{print $4}'`
  13.     IDLE2=`cat /proc/stat | grep "cpu " |  awk '{print $5}'`
  14.     IOWAIT2=`cat /proc/stat | grep "cpu " |  awk '{print $6}'`
  15.     IRQ2=`cat /proc/stat | grep "cpu " |  awk '{print $7}'`
  16.     SIRQ2=`cat /proc/stat | grep "cpu " |  awk '{print $8}'`
  17.  
  18.     USER=`expr ${USER2} - ${USER1}`
  19.     NICE=`expr ${NICE2} - ${NICE1}`
  20.     SYSTEM=`expr ${SYSTEM2} - ${SYSTEM1}`
  21.     IDLE=`expr ${IDLE2} - ${IDLE1}`
  22.     IOWAIT=`expr ${IOWAIT2} - ${IOWAIT1}`
  23.     IRQ=`expr ${IRQ2} - ${IRQ1}`
  24.     SIRQ=`expr ${SIRQ2} - ${SIRQ1}`
  25.  
  26.     USED=`expr ${USER} + ${NICE} + ${SYSTEM} + ${IOWAIT} + ${IRQ} + ${SIRQ}`
  27.     TOTAL=`expr ${USED} + ${IDLE}`
  28.  
  29.     echo "scale=2; (${USED} * 100/${TOTAL})"
  30.     PERCENT=`echo "scale=10; (${USED} * 100/${TOTAL})" | bc`
  31.     UPERC=`echo "scale=10; (${USER} * 100/${TOTAL})" | bc`
  32.  
  33.     INDATA=`printf "%0.2f" ${UPERC}`
  34.     OUTDATA=`printf "%0.2f" ${PERCENT}`
  35.  
  36. echo ${INDATA}
  37. echo ${OUTDATA}
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top