Capturing first output from 'top'-likes command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capturing first output from 'top'-likes command
# 1  
Old 12-22-2011
Capturing first output from 'top'-likes command

Is this a stupid code??

Code:
top > top.out &
sleep 2
kill %1
cat top.out

Thanks,
# 2  
Old 12-22-2011
May be you need this?

Code:
top -n 1 > top.out

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 12-22-2011
Yes. Also "kill %1" is a syntax error.
Please post your Operating System and version and if it didn't come with "top", where you got "top" from.
There are many and various versions of "top" but most of them have command line options. A properly installed one will have "man top".

e.g. In my version the "-d 1" parameter makes "top" exit after one interation.
Code:
top -d 1

In practice you can usually get anything which is a displayed my "top" from standard unix commands (and in an easier to process format).


Now: ahmed101 must have a different version of "top" because in my version "-n 1" would only display one process.
This User Gave Thanks to methyl For This Post:
# 4  
Old 12-22-2011
The command is not 'top' and no command line options. Just top-like command.
It displays third-party app. engine's status and re-display every 1-second....

Thanks,
# 5  
Old 12-22-2011
top and other interactive commands like it are prone to create outputs full of escape sequences that are difficult to view without a terminal, no matter how they're captured.

top itself can do this, so you don't need to kill it:
Code:
top -n 1 > output

---------- Post updated at 11:21 AM ---------- Previous update was at 11:19 AM ----------

Quote:
Originally Posted by Shawn, Lee
The command is not 'top' and no command line options. Just top-like command.
It displays third-party app. engine's status...

Thanks,
If it works, it's not stupid, but whether and how well it will work depends on the application. The output might not be very readable without a terminal. It'd be better to get the output with the application's cooperation, if possible.

'cat myapp.out' may be misleading. When you do that in a terminal, the terminal will interpret escape sequences for you and present the output properly. But if you try sending that to a printer, or process it with commandline tools, you could find it full of gibberish.

Code:
myapp > myapp.out &
PID=$!
sleep 2
kill $PID
less myapp.out


Last edited by Corona688; 12-22-2011 at 02:09 PM.. Reason: thanks methyl
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 12-22-2011
If this application has a keyboard stop command, you could try typeahead:
The "cat -v" command demonstrates that the output from "top" contains all sorts of screen control characters.
Code:
(sleep 1;echo "q") | top > top.out
cat -v top.out


Aside: In correcting your "kill" command, Corona688 probably meant:
Code:
myapp > myapp.out &
PID=$!
sleep 2
kill ${PID}
less myapp.out

These 2 Users Gave Thanks to methyl For This Post:
# 7  
Old 12-22-2011
I'm really appreciate your replies.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unable to scroll to the top of the output of a command

Hello, I am a beginner, I have currently Solaris 11 on a vmware machine. Whenever I type a command like 'ls' the screen scrolls to the end of the screen. I am unable to see the entire list of directories and files. I have tried ls |page command, but looking out for a better option. (3 Replies)
Discussion started by: farheenprasad
3 Replies

2. Shell Programming and Scripting

Format Top and prstat command output

need help with formatting output of command top and prstat. My requirment is to remove few columns and display remaining . But when i used awk to do that the output seems to be have gone vague, mixing the column values. After using awk to print particular column the output seems to have lost... (1 Reply)
Discussion started by: NarayanaPrakash
1 Replies

3. UNIX for Advanced & Expert Users

Conflicts in the output of TOP command

Hi All, In the output of TOP command in my unix system, i monitored that some process has utilization more than 100% even some process has 4000% utilisation. Please help me understand how it is possible to show more than 100% utilization. Please see the screenshot below:... (2 Replies)
Discussion started by: anand2308
2 Replies

4. HP-UX

Sorting top command output in HP_UX 11.11

Hello all, I've been woking on Solaris and Linux (Red Hat) so far but now I've inherited an HP-UX system and having minor issues with syntax...Appreciate if you could help me out here.. 1) I'm trying to sort the output of the top command in HP-UX 11.11 by pressing O (capital O) after typing... (2 Replies)
Discussion started by: luft
2 Replies

5. Shell Programming and Scripting

Need help with shell script - output of top command

I have written shell script to send file as an attachemt of email and output of "top -o res" command as email body. it works fine if i execute manually from prompt but it does not send "top -o res" command output in email body when it is executed via crontab. Any suggestions. My script is below:... (5 Replies)
Discussion started by: needyourhelp10
5 Replies

6. Shell Programming and Scripting

Extract header from top command output

hi, I want to extract and save the cpu(s) information from top command output, but individual cpu statistics separately on a multi-processor machine. In command line, top will show this statistics when we press the switch "1". any ideas? thanks, meharo (3 Replies)
Discussion started by: meharo
3 Replies

7. Shell Programming and Scripting

capturing output from top and format output

Hi all, I'd like to capture the output from the 'top' command to monitor my CPU and Mem utilisation.Currently my command isecho date `top -b -n1 | grep -e Cpu -e Mem` I get the output in 3 separate lines.Tue Feb 24 15:00:03 Cpu(s): 3.4% us, 8.5% sy .. .. Mem: 1011480k total, 226928k used, ....... (4 Replies)
Discussion started by: new2ss
4 Replies

8. Shell Programming and Scripting

Capturing the output from an exec command

Hi, I'm new to ksh - unix platform. I'm writing a small script which will search my current directory and will search for file names which it takes input from the users. Here is the code I'm having. 1 #!/bin/ksh 2 echo "enter a file name to be searched in the current dir : " 3 read... (1 Reply)
Discussion started by: avik
1 Replies

9. UNIX for Dummies Questions & Answers

Capturing output from grpck command on AIX

I'm having trouble capturing output from the following command on AIX: grpck -n ALL > error.out It gives me the results on the screen but my file is blank. I have no trouble capturing output from "ls > ls.out", but doesn't seem to work with the grpck command. Any ideas? Thanks. (2 Replies)
Discussion started by: pdtak
2 Replies

10. Shell Programming and Scripting

Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD cd public_html/crap dir $FILE quit END_SCRIPT Where the $ variable... (2 Replies)
Discussion started by: designflaw
2 Replies
Login or Register to Ask a Question