LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to programatically feed top with key strokes (https://www.linuxquestions.org/questions/linux-software-2/how-to-programatically-feed-top-with-key-strokes-829307/)

babaqga 08-30-2010 08:13 AM

How to programatically feed top with key strokes
 
Hi fellow forumers,

I'm writing a simple bash script and I would like it to be able to to execute top (that's the easy part) and then to supply the parameters to top
programatically.

Here is the explanation:
Top is an interactive program that requires user input to do stuff, sort etc. I would like to programatically do so, for example:

top;
supply input;
get info;
quit;

Is it possible with simple bash?

Regards

druuna 08-30-2010 08:31 AM

Hi,

You are aware that top (tries to) read /etc/toprc and ~/.toprc?

If the parameters you want to give to top are always the same you could consider creating a ~/.toprc (start top, set all the options and press W).

I'm not 100% sure, but I don't think you can feed top any options once it is up and running.

Hope this helps.

babaqga 08-30-2010 08:46 AM

Quote:

Originally Posted by druuna (Post 4082335)
Hi,

You are aware that top (tries to) read /etc/toprc and ~/.toprc?

If the parameters you want to give to top are always the same you could consider creating a ~/.toprc (start top, set all the options and press W).

I'm not 100% sure, but I don't think you can feed top any options once it is up and running.

Hope this helps.

Actually, if you can't, it will be a kinda useless utility. That's why I believe it can be feeded. As there is probably a misunderstanding about what I want, here is the code:

Code:

#!/bin/bash
NRCORES=`mpstat  | grep CPU | head -n1 | awk '{print $6}' | tr -d "(" | bc`
PIDOFJAVA=`pidof java`
echo $PIDOFJAVA
echo $NRCORES
echo "Now trying to do the shit..."
exec 6<&0
exec < input
`top -p $PIDOFJAVA`
read a1
echo $a1
exec 0<&6 6<&-

the input file is in the same directory and contains only
1[newline feed]

If you reproduce the thingy in normal terminal:
Code:

top -p $PIDOFJAVA
waits for user input, and if you press one (1), it shows the cpu/memory utilization on the java process on different cores.
I want to be able to do that programatically, so user input is not required

Valery Reznic 08-31-2010 02:04 AM

Will
Code:

top -b ...
help you ?

babaqga 09-02-2010 02:54 AM

Quote:

Originally Posted by Valery Reznic (Post 4083192)
Will
Code:

top -b ...
help you ?

Will my reply:
O M G?!
answer your question.


All times are GMT -5. The time now is 11:38 AM.