Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Mettre le resultat d'une commande bash dans un tableau ?

3 réponses
Avatar
Sameline
ReBonjour,

Comment je peux faire pour utiliser la commande
"top -bn 1 | grep "httpd"", qui me sort :

4566 root 16 0 10368 4656 8396 S 0.0 0.5 0:01.75 httpd2
4576 apache 16 0 12156 7228 8432 S 0.0 0.7 0:06.82 httpd2
4577 apache 16 0 11964 7048 8432 S 0.0 0.7 0:07.25 httpd2

dans mon programme perl de façon a ce que cela me cree des tableaux style :

@top1 = ("4566","root","16","0","10368","4656","8396","S","0.0","0.5",
"0:01.75","httpd2");

@top2 = ("4576","apache","16","0","12156","7228","8432","S","0.0","0.7",
"0:06.82","httpd2");

etc ..

Merci d'avance

3 réponses

Avatar
Sameline
je change la commande car elle permet de trier les info ;=)

plutot un "ps -C httpd2 -opid,pcpu,comm"

qui sort :

[ proc]# ps -C httpd2 -opid,pcpu,comm
PID %CPU COMMAND
4566 0.0 httpd2
4576 0.0 httpd2
4577 0.0 httpd2





ReBonjour,

Comment je peux faire pour utiliser la commande
"top -bn 1 | grep "httpd"", qui me sort :

4566 root 16 0 10368 4656 8396 S 0.0 0.5 0:01.75 httpd2
4576 apache 16 0 12156 7228 8432 S 0.0 0.7 0:06.82 httpd2
4577 apache 16 0 11964 7048 8432 S 0.0 0.7 0:07.25 httpd2

dans mon programme perl de façon a ce que cela me cree des tableaux style :

@top1 = ("4566","root","16","0","10368","4656","8396","S","0.0","0.5",
"0:01.75","httpd2");

@top2 = ("4576","apache","16","0","12156","7228","8432","S","0.0","0.7",
"0:06.82","httpd2");

etc ..

Merci d'avance


Avatar
David LE BOURGEOIS
ReBonjour,


Bonjour.

Comment je peux faire pour utiliser la commande
"top -bn 1 | grep "httpd"", qui me sort :

4566 root 16 0 10368 4656 8396 S 0.0 0.5 0:01.75 httpd2
4576 apache 16 0 12156 7228 8432 S 0.0 0.7 0:06.82 httpd2
4577 apache 16 0 11964 7048 8432 S 0.0 0.7 0:07.25 httpd2

dans mon programme perl de façon a ce que cela me cree des tableaux style :

@top1 = ("4566","root","16","0","10368","4656","8396","S","0.0","0.5",
"0:01.75","httpd2");

@top2 = ("4576","apache","16","0","12156","7228","8432","S","0.0","0.7",
"0:06.82","httpd2");

etc ..


$ perl -ne '@top = split /s+/, $_; print join(",", @top), "n"' <<FIN
heredoc> 4566 root 16 0 10368 4656 8396 S 0.0 0.5 0:01.75 httpd2
heredoc> 4576 apache 16 0 12156 7228 8432 S 0.0 0.7 0:06.82 httpd2
heredoc> 4577 apache 16 0 11964 7048 8432 S 0.0 0.7 0:07.25 httpd2
heredoc> FIN
4566,root,16,0,10368,4656,8396,S,0.0,0.5,0:01.75,httpd2
4576,apache,16,0,12156,7228,8432,S,0.0,0.7,0:06.82,httpd2
4577,apache,16,0,11964,7048,8432,S,0.0,0.7,0:07.25,httpd2

Merci d'avance


De rien.

--
David LE BOURGEOIS
e-mail : david.lebourgeois (at) free.fr
jabber : david.lebourgeois (at) jabber.fr

Avatar
Loïc Restoux
Le 11 déc, à 09:55, Sameline papotait :
Comment je peux faire pour utiliser la commande
"top -bn 1 | grep "httpd"", qui me sort :

4566 root 16 0 10368 4656 8396 S 0.0 0.5 0:01.75 httpd2
4576 apache 16 0 12156 7228 8432 S 0.0 0.7 0:06.82 httpd2
4577 apache 16 0 11964 7048 8432 S 0.0 0.7 0:07.25 httpd2

dans mon programme perl de façon a ce que cela me cree des tableaux style :
[SNIP]


Avec une boucle for pour lire les lignes,
la fonction split pour découper les colonnes et un push pour ranger le
tout proprement dans un tableau multi-dimensionnel.

--
No fortunes found