The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > Linux > Gentoo
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SFTP in batch Mode ilok AIX 1 08-28-2007 01:25 AM
Sftp in Batch Mode sivaemn UNIX for Advanced & Expert Users 2 07-01-2007 06:52 AM
SSH in batch mode and File-Handles in a loop DaveCutler Shell Programming and Scripting 3 04-03-2007 06:39 AM
su command in batch mode Rajesh Gohad Shell Programming and Scripting 3 01-26-2007 12:54 AM
SFTP in batch mode mlim1111 Shell Programming and Scripting 5 01-23-2006 04:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-16-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
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
  #2 (permalink)  
Old 08-17-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
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 (permalink)  
Old 08-17-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
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 (permalink)  
Old 08-17-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
I see no script in that screen shot.

In what way did Franklin52's solution not work?
  #5 (permalink)  
Old 08-19-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
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
  #6 (permalink)  
Old 08-19-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
How about without the shortened delay:

Code:
top -b -n2 | awk '/^top/{i++}i==2' > somefile
  #7 (permalink)  
Old 08-20-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0