I am unable to capture CPU[3] to IDLE variable in shell script (/bin/sh)
Code snippet as below:-
while true; do
CPU=$(sed -n 's/^cpu\s//p' /proc/stat)
**IDLE=$CPU[3]** # Just the idle CPU time.
for VALUE in ${CPU} ;
do
TOTAL=$((TOTAL+VALUE))
printf "%s \n\n" $VALUE
sleep 1
printf "%s \n" $IDLE
done
sleep 0.1
done
You can try below script for extracting specific string elements from sed command.
But I see extracted value is increments by one , I will look into this and update in a while , Good Luck !!!
I am getting Output as below: