Google Groups Home Help | Sign in
Message from discussion awk print system date and time
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
moonhkt  
View profile
 More options May 8, 3:18 am
Newsgroups: comp.unix.shell
From: moonhkt <moon...@gmail.com>
Date: Thu, 8 May 2008 00:18:53 -0700 (PDT)
Local: Thurs, May 8 2008 3:18 am
Subject: awk print system date and time
Hi All
I am using awk for reformat vmstat data.
Do you know to print system date and time

my outout as below. the the time value no change ? Always
20080508_151351 in below session

Interval=2 , Count=20
System Configuration: lcpu=4 mem=7817MB
memory         page
faults                 cpu
-------------- -------------------------------------
---------------------- ------------
 r  b   avm     fre   re   pi   po    fr      sr     cy     in
sy    cs us sy id wa
 6 14  1314292  327    0    6   10   330 3490429    120   1978  20213
1771 36 46  1 17    20080508_151351
 7 13  1313730  362    0    9    9   296 1553745     58   1766  47794
1872 57 34  0  9    20080508_151351
 6 13  1313130  443    0    6    0   190 1598586     50   1769  56427
1825 62 30  0  8    20080508_151351
 4 14  1313181  333    0    4    2   262 3460351    112   1978  34615
1660 51 41  0  8    20080508_151351
 6 17  1313356  324    0    7    3   344 3125466    112   1951  25643
1589 53 42  0  4    20080508_151351
10 16  1313704  330    0   16   20   565 3530416    135   2050  41217
1735 52 45  0  2    20080508_151351
13 14  1314643  922    0   51   48  1277 1581288     62   1904  44890
2296 68 28  0  4    20080508_151351
 9 14  1315012  323    0   19   23   258 2228074     87   1968  79867
2040 66 32  0  2    20080508_151351

PROCESS ()
{
# Interval , Count

echo  Interval=$INT , Count=$CNT
(( CNT_A = CNT - 1 ))
TIME=`date +%Y/%m/%d.%H:%M:%S`
vmstat ${INT} ${CNT}| awk -v CYC=${CNT_A} -v TX="$TIME" '
    NR == 1 { print $0 }
    NR == 2 { print("memory
page                                  faults                 cpu")
              print("--------------
------------------------------------- ----------------------
------------"
)
            }
    NR == 3 { print(" r  b   avm     fre   re   pi   po    fr
sr     cy     in     sy    cs us sy id wa "
)   }
    # NR == 4 { print("-- --  ------- ----- --- ---- ---- ----- ------
----- ----- ----- ----- -- -- -- -- ")}
    NR == 5 { next }
   {
    if($1 ~ /^[0-9].*/) {
       dt="'`date +%Y%m%d_%H%M%S`'"
       printf ("%2s %2s %8s %4s %4s %4s %4s %5s %7s %6s %6s %6s %5s
%2s %2s %2s %2s %18s\n",

$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,dt)
      (totr+=$1);
      (totb+=$2);
      (totavm+=$3);
      (totfre+=$4);
      (totpi+=$6);
      (totpo+=$7);
      (totfr+=$8);
      (totsr+=$9);
      (totsy+=$14+$15);
      (totid+=$16+$17);
    }
    (avr=totr/CYC)
    (avb=totb/CYC)
    (avavm=totavm/CYC)
    (avfre=totfre/CYC)
    (avpi=totpi/CYC)
    (avpo=totpo/CYC)
    (avfr=totfr/CYC)
    (avsr=totsr/CYC)
    };
END {
     avecpu=(totsy)/(totsy+totid) * 100
     aveid=100 - avecpu
     avr=int(avr)
     avb=int(avb)
     avpi=int(avpi)
     avpo=int(avpo)
     avfr=int(avfr)
     avsr=int(avsr)
           printf ("%2s %2s %8.0f %4.0f %4s %4s %4s %5s %7s %6s %6s
%6s %5s %2s %2s %2s %2s SUM %15s\n",
              avr,avb,avavm,avfre,$5,avpi,avpo,avfr,avsr,
$10,$11,$12,$13,$14,$15,$16,$17,TX)
     print "\nSummary"
     print "The average usage of CPU is           : " avecpu "%"
     print ("");

}'
}


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google