PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > awk print system date and time
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

awk print system date and time

Réponse
 
LinkBack Outils de la discussion
Vieux 08/05/2008, 08h18   #1
moonhkt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 ("");
}'
}
  Réponse avec citation
Vieux 08/05/2008, 12h41   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.

> 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 ("");
> }'
> }


  Réponse avec citation
Vieux 08/05/2008, 12h46   #3
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Vieux 08/05/2008, 15h39   #4
moonhkt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk print system date and time

On May 8, 7:46 pm, pk <p...@pk.invalid> wrote:
> 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.


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


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h16.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14254 seconds with 12 queries