Google Groups Home
Help | Sign in
awk print system date and time
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
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
(1 user)  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 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.
Ed Morton  
View profile
(1 user)  More options May 8, 7:41 am
Newsgroups: comp.unix.shell
From: Ed Morton <mor...@lsupcaemnt.com>
Date: Thu, 08 May 2008 06:41:15 -0500
Local: Thurs, May 8 2008 7:41 am
Subject: Re: awk print system date and time
On 5/8/2008 2:18 AM, moonhkt wrote:

> 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

What makes you think your command takes more than 1 second to run?

        Ed.


    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.
pk  
View profile
 More options May 8, 7:46 am
Newsgroups: comp.unix.shell
From: pk <p...@pk.invalid>
Date: Thu, 08 May 2008 13:46:32 +0200
Local: Thurs, May 8 2008 7:46 am
Subject: Re: awk print system date and time
On Thursday 8 May 2008 13:41, Ed Morton wrote:

> On 5/8/2008 2:18 AM, moonhkt wrote:
>> 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

> What makes you think your command takes more than 1 second to run?

He's running "vmstat 2 20" which outputs a line every two seconds, and pipes
the output to awk.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.


    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.
moonhkt  
View profile
 More options May 8, 10:39 am
Newsgroups: comp.unix.shell
From: moonhkt <moon...@gmail.com>
Date: Thu, 8 May 2008 07:39:23 -0700 (PDT)
Local: Thurs, May 8 2008 10:39 am
Subject: Re: awk print system date and time
On May 8, 7:46 pm, pk <p...@pk.invalid> wrote:

I think    dt="'`date +%Y%m%d_%H%M%S`'"  will get the current time.

    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.
End of messages
« Back to Discussions « Newer topic     Older topic »

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