Appending process output into a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending process output into a file
# 1  
Old 01-12-2010
Appending process output into a file

Hello Friends,

I'm trying to save process status of root user sorting by CPU usage. However i couldnt save the continuous, standard outputs into a file. Do you have any idea to do it?

Code:
prstat -u root -a -s cpu | sed -e '/^$/d;/sleep/d;/Total/d' >> stat.txt

>ls -l stat.txt
-rw-r--r-- 1 root root 0 Jan 12 17:25 stat.txt

But when i dont append the above code the result is like this:

Code:
   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP       
 20249 root     5416K 3368K cpu7    58    0   0:00:00 0.0% prstat/1
 NPROC USERNAME  SWAP   RSS MEMORY      TIME  CPU                             
    30 root       56M   72M   0.9%   2:58:22 0.0%
   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP       
 20249 root     5680K 3608K cpu9    59    0   0:00:00 0.1% prstat/1
 NPROC USERNAME  SWAP   RSS MEMORY      TIME  CPU                             
    30 root       56M   72M   0.9%   2:58:22 0.1%

Thanks in advance
# 2  
Old 01-12-2010
Hi EAGL€

All I did was add an interval, and a count, and it works OK:

Code:
# prstat -u root -a -s cpu 0 1 | sed -e '/^$/d;/sleep/d;/Total/d' >> stat.txt

# ll stat.txt
-rw-r--r--   1 root     root         341 Jan 12 16:49 stat.txt

# cat stat.txt
   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP
 14756 root     2176K 1440K cpu0    49    0   0:00:00 0.2% prstat/1
 14708 root     1832K 1296K run     39    0   0:00:00 0.1% ksh/1
 NPROC USERNAME  SWAP   RSS MEMORY      TIME  CPU
    28 root       43M   48M   4.7%   0:57:15 0.3%

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending output to file

Hi, I want to calculate std dev for a list of files and then print the output appended to an existing file. I have a few folders within the directory Folder, and I am interested in getting the std dev of values in files named as time.txt. In the last pipe, if I print just the sd value, it... (1 Reply)
Discussion started by: jamie_123
1 Replies

2. Shell Programming and Scripting

How to process select list of files and output to the same file?

Hi, I've a list of files ac_info.tps, subscription_array.tps, .......and many other files one of the file, bin_range_list.tps has the following content CREATE OR REPLACE TYPE "BIN_RANGE_LIST" AS TABLE OF BIN_RANGE_ELEM; / grant execute on... (4 Replies)
Discussion started by: jediwannabe
4 Replies

3. Shell Programming and Scripting

Appending script output to file

Hi guys, I have a script from which I would like its standard output results (upon execution) to be appended to a separate file (.txt format). How can I write such a command into the script for this to occur? I know there should be a >> involved somewhere. Thanks! (5 Replies)
Discussion started by: jjb1989
5 Replies

4. UNIX for Dummies Questions & Answers

Appending something to output before being written to a file

Hi, I'm quite stuck with what I thought should've been simple but I just can't seem to do it. Firstly, I have the following done in bourne shell: cat datafile | tr '' '' >> newfile echo "$fullfilepath" >> newfile i want to have the output of that echo put on the same line as the output... (4 Replies)
Discussion started by: Darkst
4 Replies

5. UNIX for Dummies Questions & Answers

top output for a specific process to a file

Hi, I have the following script, and it is driving me nuts. It just hangs, I've tried all kinds of tricks, but it won't work. I know it can, it is pretty straight forward. It hangs when it tries to output $X Any help appreciated! #!/bin/bash set -o xtrace command="top -b"... (10 Replies)
Discussion started by: Bloke
10 Replies

6. Shell Programming and Scripting

Write process output to a file

When I run <ls -l> to get a list of all the files, I want the displayed result to be written to a text file. Is there a way to do that? (1 Reply)
Discussion started by: kn.naresh
1 Replies

7. Shell Programming and Scripting

capturing line from script output and appending to a file

Hi all, I did some searching in this forum but can't find anything that matches the issue I'm bumping heads with. On a CentOS4/Postfix (and bash everywhere) mail gateway box I run a command periodically to purge the Postfix queue of messages "From:MAILER-DAEMON". This is the one line'r... (6 Replies)
Discussion started by: wally_welder
6 Replies

8. Shell Programming and Scripting

appending to sed output of one file into the middle of file

hi, i have a file file1 file2 ----------- ----------------- aa bbb ccc 111 1111 1111 ddd eee fff 222 3333 4444 ggg hhh... (5 Replies)
Discussion started by: go4desperado
5 Replies

9. UNIX for Dummies Questions & Answers

Opening output file while still in process

Dear guru, Say I have a long process that is executed in this way: $ nohup perl mycode.pl > output.txt & Now if I want to view the output file with vi, while process still running: $ vi output.txt Will it kill the process? (seems to me it does). If so how can view the file without... (4 Replies)
Discussion started by: monkfan
4 Replies
Login or Register to Ask a Question