GNU/Linux >> Tutoriels Linux >  >> Linux

Comment ajouter un horodatage à la sortie de la commande Unix Vmstat

Question : La sortie Vmstat n'affiche pas la date et l'heure, ce qui est pénible lorsque vous essayez de stocker la sortie vmstat pour effectuer une analyse des performances.

Alors, comment ajouter un horodatage à la sortie Linux vmstat ?

Réponse : Vous pouvez afficher l'horodatage sur chaque ligne de la sortie de la commande vmstat en utilisant un simple script perl comme indiqué ci-dessous.

Sortie Vmstat par défaut (sans horodatage)

$ vmstat 1 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0  33308 450080  59020 6757044    1    1   551   148    1     6 26  9 60  5
 0  0  33308 449960  59020 6757044    0    0     0     0 1068  1576  1  1 98  0
 1  0  33308 453928  59020 6757044    0    0     0    48 1049  1628  2  1 97  0
 0  0  33308 454120  59020 6757044    0    0     0     0 1034  1663  2  1 96  0
 0  0  33308 454112  59020 6757044    0    0     0     0 1025  1535  1  1 98  0

Sortie Vmstat avec horodatage

Créez le fichier timestamp.pl simple suivant

$ vi timestamp.pl
#!/usr/bin/perl
while (<>) { print localtime() . ": $_"; }

Dirigez maintenant la sortie de la commande vmstat vers ce timestamp.pl pour afficher l'horodatage comme indiqué ci-dessous.

$ vmstat 1 5 | timestamp.pl
Sat Aug 22 20:50:36 2009: procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
Sat Aug 22 20:50:36 2009:  r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
Sat Aug 22 20:50:36 2009:  2  0  33308 452080  59084 6761140    1    1   551   148    1     6 26  9 60  5
Sat Aug 22 20:50:37 2009:  0  0  33308 454368  59084 6761140    0    0     0     0 1028  1713  2  1 96  0
Sat Aug 22 20:50:38 2009:  0  0  33308 454368  59084 6761140    0    0     0     0 1010  1432  0  0 100  0
Sat Aug 22 20:50:39 2009:  0  0  33308 454368  59084 6761140    0    0     0    12 1021  1481  1  0 99  0
Sat Aug 22 20:50:40 2009:  0  0  33308 457184  59084 6761140    0    0     0     0 1029  1549  1  1 98  0

Linux
  1. Comment affecter la sortie d'une commande à une variable Shell ?

  2. Comment fonctionne la commande Exit sur un terminal Unix ?

  3. Comment capturer la sortie de la commande supérieure Unix dans un fichier au format lisible

  4. Comment nettoyer la sortie de la commande Linux 'script'

  5. Comment fonctionnent les options '-s', '-t' et '-c' de la commande tr sous Unix ?

Comment utiliser la commande grep sous Linux/UNIX

Comment activer l'horodatage dans la sortie de la commande d'historique Linux

Comment enregistrer la sortie de la commande Linux dans une image ou un fichier texte

Comment activer l'horodatage dans l'historique de Bash sous Linux

Comment rediriger la sortie de la commande shell

7 exemples de commande de route Linux (comment ajouter une route sous Linux)