![]() |
top command
i want to run top command every 1 second interval and want to store the output in a text file. so in every 1 second interval my text file should be overwritten by the new fresh output data.
my top command is : top -d -1 Question is : How do i store the output in a text file and how do they be overwritten by the fresh output data in every 1 secs interval ? my system is red hat 9 |
top -d 1 >~/.top_logfile
will output the contents of top once every second to the file you specify, in this case, .top_logfile in your home directory. |
isn't there a file that does this already? somewhere in /proc? you could just cp that file every 1 second or so
|
>will output the contents of top once every second to the file you specify, in this >case, .top_logfile in your home directory.
will it overwrite everytime ? or the new results will be apppended ? i want the results should be overwritten everytime. >isn't there a file that does this already? somewhere in /proc? you could just cp >that file every 1 second or so i may change 1 seconds to 4 seconds later on. i may customize it . so, i dont want the default log file . |
" command >file "
will overwrite " command >>file " will append |
top -d 1 > logfile
does not do what he wants (doesn't even produce correct results), neither does top -d 1 -b > logfile since the new content is appended every second, nothing is overwritten (except for the content of logfile at the beginning). |
One > is overwrite, two >> is append; append means add to the end.
Works fine on my system. |
This seems to work a little better...
Code:
perl -e 'while(1) {`top -b -n 1 > testfile`;sleep(1)}' |
Quote:
|
yea, > will overwrite every time you run the command, but by just using:
> top -d 1 > file.txt top is continuing to run, so tile.txt is never closed and reopend for overwriting. |
Code:
top -d 1 >~/.top_logfile |
hi,
it is not working ! it is not overwriting at all . its appending ! command was top -d -1 >log.txt i just need to get the fresh data every 1 secs interval from the log.txt file. so, i told it to be overwritten the content . i dont like append, if i append my file is going to be larger and t would be difficult to read the last status . but surprisingly. i ran the above command and got my file appeneded to 1.4 MB !! . then i stopped the execution by CTRL+C . |
how do i overwrite the file content in every 1 secs interval ? is it not possible in RED HAT 9 ?
|
Try reading my reply!!
|
Yeah, puffinman's is the best answer in this group. The tilde specifies your home directory (~/) just for convenience.
|
All times are GMT -5. The time now is 03:10 PM. |