I am trying to calculate the CPU load of a processor using the steps found here. I managed to do this:
cat /proc/stat | head -n 1 | awk '{print ($5+$6, $2+$3+$4+$7+$8+$9)}' | awk '{print($1,$1+$2)}' This gives me the values I need. However, I need to calculate the same values a second later and then use both of these results to calculate the final load. That means, that I need to do something like this:
cat /proc/stat | calculate something | awk '{print($1,$1+$2)}' ; sleep for a second; calculate again; use both of the results Is there a way for me to save the variables $1 and $1+$2 in the first awk call, so that I can use them later? I cannot use a bash script, it needs to be done in a command line.
bash script, it needs to be done in a command lineCommand line is bash, it's the same.hat I need to do somethingSo do exactly that.a=$(....); sleep 1; b=$(...); echo use $a and $b.it needs to be done in a command line.? everytime you need to perform this operation ... are you going to manually type it at the command prompt? wouldn't it make more sense to place it in a script that can be executed repeatedly (without the need to do all that typing, or to introduce syntax/logic errors with manual typing)? even placing the logic into a function (a type of 'script'; see EdMorton's answer) would be of use