Home > Net >  Bash Script to Monitor CPU clock speed
Bash Script to Monitor CPU clock speed

Time:07-31

I made a simple program but it prints all CPU speeds on ONE line... Any suggestions how to make each CPU print on its own line?

#!/bin/bash

while [ 1 ]
    do 
        my_array=( $(cat /proc/cpuinfo | grep MHz) )
        printf '%s\033[A\n%s\033[A\n%s\033[A\n%s\033[A\n' "${my_array[*]}"
        sleep 1
    done


CodePudding user response:

You can use

watch "cat /proc/cpuinfo | grep MHz"

CodePudding user response:

You could use

#!/bin/bash

while [ 1 ]
    do.
        IFS="\n"
        my_array=( $(cat /proc/cpuinfo | grep MHz) )
        for item in ${my_array[*]}
         do
          echo ${item}
          sleep 1
          clear
        done
    done

Pay attention to the IFS variable. IFS=$'\n' (newline) is required to interpret each line from the multiline grep output as a new array item.

By default, IFS is [::space::] or not defined.

  • Related