(Last Updated On: February 24, 2017)

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.

More great Linux goodness!

Jed Reynolds
Jed Reynolds has been known to void warranties and super glue his fingers together. When he is not doing photography or fixing his bike, he can be found being a grey beard programmer analyst for Candela Technologies. Start stalking him at https://about.me/jed_reynolds.

Written by Jed Reynolds

Jed Reynolds has been known to void warranties and super glue his fingers together. When he is not doing photography or fixing his bike, he can be found being a grey beard programmer analyst for Candela Technologies. Start stalking him at https://about.me/jed_reynolds.

1
Leave a Reply

Please Login to comment
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jed Reynolds Recent comment authors
  Subscribe  
newest oldest most voted
Notify of