LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-30-2010, 08:13 AM   #1
babaqga
LQ Newbie
 
Registered: Aug 2010
Posts: 18

Rep: Reputation: 1
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
 
Old 08-30-2010, 08:31 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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.
 
Old 08-30-2010, 08:46 AM   #3
babaqga
LQ Newbie
 
Registered: Aug 2010
Posts: 18

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by druuna View Post
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
 
Old 08-31-2010, 02:04 AM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 666

Rep: Reputation: 132Reputation: 132
Will
Code:
top -b ...
help you ?
 
Old 09-02-2010, 02:54 AM   #5
babaqga
LQ Newbie
 
Registered: Aug 2010
Posts: 18

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Valery Reznic View Post
Will
Code:
top -b ...
help you ?
Will my reply:
O M G?!
answer your question.
 
  


Reply

Tags
top


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
USB keyboard - Capture key strokes/input v333k Linux - Software 2 10-19-2009 01:44 PM
Midnight Commander requires twice the key-strokes jsmith6 Slackware 13 05-19-2006 03:47 PM
problem recognising key strokes himateja Programming 3 05-27-2005 05:54 AM
Identifying and Mapping/Binding key strokes mikeyt_333 Linux - General 3 10-02-2003 10:42 PM
Repeating key strokes toxic53 Linux - General 1 12-11-2002 09:06 PM


All times are GMT -5. The time now is 03:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration