Friday, August 26, 2016

Write Your Own CPU Meter in Bash

Here’s a fun little project that is a pretty good combination of array use and pattern manipulation.

Screenshot of Bash CPU Meter

Bash CPU Meter

#!/bin/bash
function get_mhz() {
   while read line; do
      if [[ $line =~ cpu\ MHz ]]; then
         local hunks=(${line})
         local ahz=(${hunks[3]})
         local bars=$(( (${ahz%%.*} * (${COLUMNS} - 12) )/3500))
         printf "%s:%${bars}s\n" $ahz '=' | tr ' ' '=' 
      fi  
   done < /proc/cpuinfo
}
while [[ 1 = 1 ]]; do
   stty_line=(`stty size`)
   COLUMNS=${stty_line[1]}
   get_mhz | sort -rn 
   echo ""
   sleep 1
done

I could go on and on about it, but I’d rather you just ask me questions.

The post Write Your Own CPU Meter in Bash appeared first on Freedom Penguin.



from Freedom Penguin http://ift.tt/2bqV0hL
via IFTTT

No comments:

Post a Comment

Playing Grand Theft Auto Inside A Neural Network’s Hallucination? It’s Possible!

Ever imagined what a Neural Network's hallucination would look like? The post Playing Grand Theft Auto Inside A Neural Network’s Halluc...