Unix/Linux Go Back    


Gentoo Gentoo Linux is a versatile and fast, completely free Linux distribution geared towards developers and network professionals.

top in batch mode, cpu info is wrong

Gentoo


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-16-2008
broli's Unix or Linux Image
broli broli is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 23 July 2014, 5:32 PM EDT
Location: Argentina
Posts: 219
Thanks: 0
Thanked 0 Times in 0 Posts
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
http://www.unix.com/linux/75765-cpu-...-hard-way.html
Sponsored Links
    #2  
Old Unix and Linux 08-17-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 18 January 2017, 8:05 AM EST
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts
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
Sponsored Links
    #3  
Old Unix and Linux 08-17-2008
broli's Unix or Linux Image
broli broli is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 23 July 2014, 5:32 PM EDT
Location: Argentina
Posts: 219
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Franklin52 View Post
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!
    #4  
Old Unix and Linux 08-17-2008
Annihilannic Annihilannic is offline Forum Advisor  
 
Join Date: May 2008
Last Activity: 28 October 2009, 7:03 PM EDT
Location: Sydney, Australia
Posts: 1,009
Thanks: 0
Thanked 2 Times in 2 Posts
I see no script in that screen shot.

In what way did Franklin52's solution not work?
Sponsored Links
    #5  
Old Unix and Linux 08-19-2008
broli's Unix or Linux Image
broli broli is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 23 July 2014, 5:32 PM EDT
Location: Argentina
Posts: 219
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Annihilannic View Post
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
Sponsored Links
    #6  
Old Unix and Linux 08-19-2008
Annihilannic Annihilannic is offline Forum Advisor  
 
Join Date: May 2008
Last Activity: 28 October 2009, 7:03 PM EDT
Location: Sydney, Australia
Posts: 1,009
Thanks: 0
Thanked 2 Times in 2 Posts
How about without the shortened delay:


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

Sponsored Links
    #7  
Old Unix and Linux 08-20-2008
broli's Unix or Linux Image
broli broli is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 23 July 2014, 5:32 PM EDT
Location: Argentina
Posts: 219
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Annihilannic View Post
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
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
FTP in batch mode cvsanthosh Shell Programming and Scripting 6 04-18-2012 03:50 AM
how to run glance over ssh in batch mode delphys HP-UX 5 10-20-2011 04:47 PM
How to run VI in batch mode grossgermany Shell Programming and Scripting 5 04-04-2010 10:12 AM
Sftp in Batch Mode sivaemn UNIX for Advanced & Expert Users 2 07-01-2007 07:52 AM



All times are GMT -4. The time now is 09:58 AM.