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 > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Capturing the output from an exec command avik Shell Programming and Scripting 1 11-07-2008 04:09 AM
Capturing output from grpck command on AIX pdtak UNIX for Dummies Questions & Answers 2 03-05-2008 02:58 PM
Capturing output from C++ program GMMike UNIX for Dummies Questions & Answers 3 03-08-2005 09:04 AM
capturing output in script MizzGail Shell Programming and Scripting 6 06-02-2004 07:44 AM
Capturing cli Program output Christopher High Level Programming 1 12-06-2001 11:08 AM

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 02-24-2009
new2ss new2ss is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 133
capturing output from top and format output

Hi all, I'd like to capture the output from the 'top' command to monitor my CPU and Mem utilisation.Currently my command is
Code:
echo date
`top -b -n1 | grep -e Cpu -e Mem`
I get the output in 3 separate lines.
Code:
Tue Feb 24 15:00:03
Cpu(s): 3.4% us, 8.5% sy .. ..
Mem: 1011480k total, 226928k used, ...
. My desired output is
Code:
Tue Feb 24 15:00:03 3.4% 8.5% ... 1011480k 226928k
I have tried to use awk to process the output from the grep
Code:
tob -b -n1 | grep -e Cpu -e Mem | awk '{print $2 $4
and I only the figures I required, but the output still spans 3 lines
Code:
2.8% 7.0%
1011480k 227896k
How should I modify the awk command to get everything on one line with the date at the front ?
  #2 (permalink)  
Old 02-24-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Code:
date| cut -d" " -f1-4; top -b -n1 | awk '/^Cpu/ {print $2,$4,$6,$8} /^Mem/ {print $2,$4}'
  #3 (permalink)  
Old 02-24-2009
new2ss new2ss is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 133
Hi zaxxon, thank you for your prompt response.

I followed your suggestion and i got the output in 3 lines. Any suggestions to get the 3 lines combined into 1 line?
  #4 (permalink)  
Old 02-24-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Code:
A=`date| cut -d" " -f1-4; top -b -n1 | awk '/^Cpu/ {print $2,$4,$6,$8} /^Mem/ {print $2,$4}'`
echo $A
Di 24. Feb 12:27:50 0.1% 0.0% 0.1% 0.0% 1003060k 982620k
  #5 (permalink)  
Old 02-24-2009
new2ss new2ss is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 133
Hi zaxxon,

thank you for your suggestion.
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 08:43 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