top in batch mode, cpu info is wrong


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
top in batch mode, cpu info is wrong

well. the title says it all.
im runing top in batch mode like this
Code:
top -b -n1 > somefile

but the cpu usage info is not correct.
if i run top normally, the first second, i see the same wrong info, and then it corrects itself.
i found only one small mention of it on this forum. with this link
top(1): tasks - Linux man page
in the bugs section, it says to use a env variable called CPULOOP, but my top is not paying attention

the system is gentoo
Code:
cat /etc/gentoo-release 
Gentoo Base System release 1.12.11.1

Code:
top -V
top: procps version 3.2.7

if i run 2 iterations of top like this
Code:
top -b n2 > somefile

then the info is ok the second time, but the "somefile" file gets 2 times the output, so, in my script, when i sort it and search for it, the info is duplicated !!!

so any help on how to fix this would be greatly apreciated
pd: the that uses top is the one been discused here
https://www.unix.com/linux/75765-cpu-...-hard-way.html
# 2  
If the second iteration is correct you can shorten the delay with the -d option and print the result of the second iteration with awk, this works on a Debian Linux system:

Code:
top -b -n2 -d0.01 | awk '/^top/{i++}i==2' > somefile

Regards
# 3  
Quote:
Originally Posted by Franklin52
If the second iteration is correct you can shorten the delay with the -d option and print the result of the second iteration with awk, this works on a Debian Linux system:

Code:
top -b -n2 -d0.01 | awk '/^top/{i++}i==2' > somefile

Regards
thanks, but it didnt worked :/

this is a screenshot of my script (below) and top at the same time.
screenshot on Flickr - Photo Sharing!
# 5  
Quote:
Originally Posted by Annihilannic
I see no script in that screen shot.

In what way did Franklin52's solution not work?
sorry, that was my mistake.
the screenshot is of my script runing.
between the terminal and the fluxbox panel, you can see 2 lines of colored text.

that is dzen.
the first number after CPU is the iddle percentage.

and what frankling said didnt worked because the problem persisted.

if i run
Code:
while : 
do
   top -b -n1 > file
   cat file
done

and top, at the same time, looking at both at the same time
the one in the while loop show an iddle percentage of 56, when top in normal mode (and any other app to check cpu usage) show the pc in 96 iddle time
# 7  
Quote:
Originally Posted by Annihilannic
How about without the shortened delay:

Code:
top -b -n2 | awk '/^top/{i++}i==2' > somefile

im having trouble understanding that awk sentence .
it searchs for a line begening with "top", and when is found, increment i,and if i equals to 2 .....

if you are trying to use awk to filter the output to get the same result as one run, then why....., shouldnt there be a print somewhere ?

similar to this?
Code:
top -b -n2 | awk ' /^top/  { i++ } \
                          i == 2 {print }' > somefile

that makes me wonder, if tops output is always the asme lenght ...
i could use something like NR >= $(top height)

keep in mind that im trying to fit all this in one awk, but each day it gets more complicated
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
FTP in batch mode
cvsanthosh
HI, Need to ftp a bunch of files in a directory in batch mode. TRying to ftp a single file first with below code. #!/bin/ksh function ftp_files { ftp -n ${D2_SRVR} <<-EOF quote user ${D2_UID} quote pass ${D2_PWD} cd ${D2_DIR}/${D2_NAME} lcd ${D1_DIR}/${D1_NAME}/dml/ put file1 ...... Shell Programming and Scripting
6
Shell Programming and Scripting
How to run VI in batch mode
grossgermany
Hi how do I use vi to do change some strings in a shell script loop 1. Run ls first, for each file that contains the word salesreport*.txt, do the following 2. use vi to run the following ex command : "1,$s/1975/1945/ig, wq" Please tell me how to do this in vi, not sed. Thank you.... Shell Programming and Scripting
5
Shell Programming and Scripting
Need a list of top 10 CPU using processes (also top 10 memory hogs, separately)
thenomad
Okay, I am trying to come up with a multi-platform script to report top ten CPU and memory hog processes, which will be run by our enterprise monitoring application as an auto-action item when the CPU and Memory utilization gets reported as higher than a certain threshold I use top on other...... AIX
5
AIX
how to get persistant cpu utilization values per process per cpu in linux (! top,ps)
pankajd
hi, i want to know cpu utilizatiion per process per cpu..for single processor also if multicore in linux ..to use these values in shell script to kill processes exceeding cpu utilization.ps (pcpu) command does not give exact values..top does not give persistant values..psstat,vmstat..does njot...... UNIX for Dummies Questions & Answers
3
UNIX for Dummies Questions & Answers
su command in batch mode
Rajesh Gohad
Hi, how do we change user in a shell script- batch mode. Thanks, Rajesh... Shell Programming and Scripting
3
Shell Programming and Scripting

Featured Tech Videos