LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2015, 11:15 AM   #1
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Rep: Reputation: Disabled
print values from stress to an array-syntax error {


I am currently printing out values from vmstat stress tests using this:


Code:
vmstat -a $INT $CNT | awk 'NR > 1 {print $13,$14,$15}'> vm.log_$D & sleep 5 && stress --vm $cores -t $seconds_to_run
I think it might be tidier to print them out in arrays but when I do, I always get a syntax error of { missing even when there isn't. How can I convert this to print the values of column $13,$14$15 through using arrays rather than the way above?


The output of both should be the same but I feel the arrays look tidier in terms of output.

Last edited by rmcateer; 03-01-2015 at 12:42 PM. Reason: add code tags
 
Old 03-02-2015, 03:56 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
do you mean something like this:
awk ' NR>1 { printf "%s,%s,%s\n", $13, $14, $15; }'
I think you missed an & before sleep (should be doubled)
 
Old 03-02-2015, 07:25 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Unless you first place those 3 values in an array you will not be able to print it out as an array as there is no built in array variable containing the information.
So your current method or pan64's are the most straight forward ways.
 
Old 03-04-2015, 06:26 AM   #4
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Original Poster
Rep: Reputation: Disabled
what about for outputting sar -d 1 10? I am trying to stress the disk and output those results in a command, which I will then graph in excel. But when I use [code]awk |'NR > 1 {printf "4s%8s%8s\n",$13,$14,$15}'[/code} and
Code:
awk 'NR > 1 {OFS="\t"; print $13,$14,$15}'
the output is unreadable like below:

Code:
   4296roryhbmc
    1944    rootal,
    3361    root
Tasks:     326total,
Cpu(s):25.7%us,54.1%sy,
Mem:2041916k
Swap:1046524kt    0 |   0     0 |   0     0 | 268   957 
 34  17  49   0   0   0|   0     0 |   0     0 |   0     0 | 279   679 
 49  31  21   0   0   0|   0     0 |   0     0 |   0     0 | 334  1874 
  4   6  90   0   0   0|   0     0 |   0     0 |   0     0 | 109   131 
 28  16  55   1   0   0|   0  4096B|   0     0 |   0     0 | 304   575 
 42  33  26   0   0   0|  20k  428k|   0     0 |   0     0 | 392  1343 
  4  10  86   0   0   0|   0     0 |   0     0 |   0     0 |  81   124 
  8  12  57  22   0   0|   0     0 |   0     0 |   0     0 | 113   193 
  2   9  66  22   0   0|   0     0 |   0     0 |   0     0 |  74   126 
  4  12  84   0   0   0|   0     0 |   0     0 |   0     0 |  92   140 
  8  21  54  17   0   0|   0     0 |   0     0 |   0     0 | 129   286 
  7  11  48  33   0  
*******************************
* Choose from the following: *
*******************************
* [1] Stress the CPU. *
* [2] Stress the Memory(RAM). *
* [3] Stress the disk drive. *
* [4] Stress the  hard disk drive. *
Press A to quit.
************************
Enter your menu choice [1-4]:
I want it to filter the results in a more tidy way as below, found at http://www.ibm.com/developerworks/ai...erfmonsar.html

Code:
 
$ sar -d

SunOS unknown 5.10 Generic_118822-23 sun4u    01/22/2006

00:00:01   device       %busy   avque   r+w/s  blks/s  avwait  avserv
. cut ...
14:00:02   dad0             31     0.6      78   16102     1.9     5.3
           dad0,c            0     0.0       0       0     0.0     0.0
           dad0,h           31     0.6      78   16102     1.9     5.3
           dad1              0     0.0       0       1     1.6     1.3
           dad1,a            0     0.0       0       1     1.6     1.3
           dad1,b            0     0.0       0       0     0.0     0.0
           dad1,c            0     0.0       0       0     0.0     0.0
How can I fix this?
 
Old 03-04-2015, 10:00 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well I know nothing of sar command, but would suggest if you want to pretty up the output you will need to play with the formatting.

awk is currently giving you exactly what you told it to, ie 13, 14 and 15th fields separated by a tab for all lines greater than 1.
I would suggest you look at the printf command and the multitude of options or perhaps try a stronger tool like Perl or Ruby to manipulate the data.
 
Old 03-04-2015, 11:06 AM   #6
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Original Poster
Rep: Reputation: Disabled
I have tried but it is still giving me bother when I try other sar commands. Are there any disk related commands(I am stressing the hard disk drive) that run in a manner similar to vmstat, iostat and sar, i.e. one that can be typed and then run for a certain number of intervals and fr a certain time?
 
Old 03-05-2015, 02:47 AM   #7
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Original Poster
Rep: Reputation: Disabled
not a duplicate-I posted it as a new questions as I had a new issue. Do you know how to fix it?
 
Old 03-05-2015, 07:57 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
You might need to show a before and after picture as I do not have the data to see what your issue is. Why can you not format the data using printf or the like?

I would add that it will not probably be a quick solution, you will need to try a few iterations to get it right.
 
Old 03-22-2015, 01:58 PM   #9
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Original Poster
Rep: Reputation: Disabled
would you know how to filter iostat so that only the reads and writes print? I don't want the %idle etc data.
 
  


Reply

Tags
array, awk, bash, ubuntu 12.04



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
print values from array (Is there a better way?) awreneau Programming 2 04-29-2013 08:27 PM
[SOLVED] reference bash array values, using a variable with a value of the array name gusthecat Programming 5 03-07-2012 03:41 PM
[SOLVED] unsigned integer array syntax error in eclipse CDT Zoophobus Programming 7 12-15-2011 09:36 AM
[bash] indirect array reference to array with values containing spaces Meson Linux - Software 9 06-04-2010 09:38 PM
syntax for gdb to print elements of 2D array? johnpaulodonnell Programming 4 03-26-2007 07:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration