![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| redirected output not going to file for all cases | brdholman | UNIX for Dummies Questions & Answers | 7 | 10-10-2007 11:07 AM |
| grep data and add to file | nbananda | Shell Programming and Scripting | 5 | 09-25-2006 07:21 AM |
| Pipe Data From Grep Into A File | katinicsdad | Shell Programming and Scripting | 4 | 09-08-2006 08:20 AM |
| search for a file - errors redirected | matrixmadhan | AIX | 1 | 07-18-2005 01:12 AM |
| Saving a redirected file | JSP | UNIX for Dummies Questions & Answers | 1 | 09-27-2001 03:52 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
no data redirected to a file with top and grep - why?
HI all,
I want to capture cpu data in batch mode of "top" command and redirect to a file like this: Code:
top -b > cpu.dat But I want to capture only Cpu lines, so i have: Code:
top -b | grep ^Cpu >cpu.dat Why? Could somebody explain and help me to make it work. Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Hard to explain if we do not know input data.
Anyway - 'grep ^Cpu' should work. Empty output file tells only that there are no lines with word "Cpu" on the beggining of a line. |
|
#3
|
|||
|
|||
|
hi,
the direct answer for your 'why' is ->the output is not going to std out it is going to std err secondly how to accomplish it ->method 1 $top 2>outputOfTop or $top >& outputOfTop then $grep pattern outputOfTop ->method 2 open two terminal term1 and term2 in term1 $mkfifo pipe $top 2>pipe in term2 $grep pattern pipe make sure the working directory is same in both the terminal i hope this should work Best Regards, Rakesh UV |
|
#4
|
|||
|
|||
|
uvrakesh: if "top -b >cpu.dat" worked then the output was not being written to stderr.
My copy of top (Ubuntu Linux 7.10) writes to stdout. But it keeps on looping even with the -b option, so I don't have exactly the same version. fongthai: if top -b >cpu.dat works then does grep ^Cpu cpu.dat work? That would be a workaround at least. |
|
#5
|
|||
|
|||
|
top -b | grep ^Cpu output is sure no error, it output should be like this:
"Cpu(s): 1.7%us, 0.8%sy, 0.0%ni, 96.9%id, 0.5%wa, 0.0%hi, 0.0%si, 0.0%st Cpu(s): 0.0%us, 1.3%sy, 0.0%ni, 98.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st" i should go to stdout. I think. I tried your methods but they don't work. Any other idea? |
|
#6
|
|||
|
|||
|
Repeat: do you get these lines in the file when you do top -b >cpu.dat?
|
|
#7
|
|||
|
|||
|
Yes, I got them.
I don't want to get data first then using grep, because it make output file become a huge file. I want to run top -b for one or two days, that's the issue. |
|||
| Google The UNIX and Linux Forums |