top in batch mode, cpu info is wrong


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 08-16-2008
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  
Old 08-17-2008
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  
Old 08-17-2008
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  
Old 08-19-2008
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
# 6  
Old 08-19-2008
How about without the shortened delay:

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

# 7  
Old 08-20-2008
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
Test if Remote server is up and running before SFTP'ing files (in batch mode) Dippu Shell Programming and Scripting 2 04-28-2016 04:17 AM
How to use gpg to encrypt data in batch/non-interactive mode? calredd Shell Programming and Scripting 2 07-31-2015 03:37 PM
tftp batch mode within bash script yildiz.a Shell Programming and Scripting 1 09-27-2012 11:50 AM
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
Need a list of top 10 CPU using processes (also top 10 memory hogs, separately) thenomad AIX 5 09-23-2009 09:42 PM
CPU Info yoavbe HP-UX 3 09-12-2009 12:45 PM
how to get persistant cpu utilization values per process per cpu in linux (! top,ps) pankajd UNIX for Dummies Questions & Answers 3 10-09-2008 12:26 PM
top %CPU. praveen_b744 UNIX for Advanced & Expert Users 3 09-11-2007 08:37 AM
cpu info vijayca HP-UX 1 08-27-2007 09:51 AM
Sftp in Batch Mode sivaemn UNIX for Advanced & Expert Users 2 07-01-2007 07:52 AM
SSH in batch mode and File-Handles in a loop DaveCutler Shell Programming and Scripting 3 04-03-2007 07:39 AM
su command in batch mode Rajesh Gohad Shell Programming and Scripting 3 01-26-2007 12:54 AM
Help ! How to get elm to send multiple attachments - in batch mode anarvan UNIX for Dummies Questions & Answers 1 09-14-2005 09:41 AM