One doubt

Hi,

Can i use the shell script like this? When i am running the script it is hanging not giving me any output. I can redirect the output and then i can do the manipulations also but why this one is wrong. I am confused we can do like this or not..


#!/usr/bin/ksh

for line in `top`
 do
        cpuusage=`echo $line | cut -d " " -f7`
        memusage=`echo$line | cut -d " " -f12`
        echo "cpuusage is $cpuusage"
        echo "memusage is $memusage"
 done

Thanks

top usually runs to a tty in full screen mode. Every so often it repaints the screen by updating only the characters that changed. It jumps around the screen to do this. And it typically runs forever until you tell it to stop. These are some of the problems you will have. Some versions of top have options to make top usable like you want. On linux it would: the -b and -n options. Look at your man page foe top to see if you have something like that.

Thanks Perderabo for your input.