Bonsoir, j'ai fais un script python qui me permet d'obtenir des stats NFS tout en utilisant argparse pour pouvoir obtenir qu'une seule stat, le voici:
Donc si je lance mon script sans argument ( "python myscript.py" ), j'obtiens toute les stats (une par ligne grace au " -l ")
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import sys import subprocess import argparse parser = argparse.ArgumentParser() parser.add_argument("-a", action='store_true', help="access stats") parser.add_argument("-c", action='store_true', help="close stats") parser.add_argument("-r", action='store_true', help="read stats") parser.add_argument("-w", action='store_true', help="write stats") args = parser.parse_args() if len(sys.argv)==1: subprocess.Popen("nfsstat -l", shell=True) elif args.a: subprocess.Popen("nfsstat -l | grep 'access:' | awk '{print $5}' ", shell=True) elif args.c: subprocess.Popen("nfsstat -l | grep 'close:' | awk '{print $5}' ", shell=True) elif args.r: subprocess.Popen("nfsstat -l | grep 'read:' | awk '{print $5}' ", shell=True) elif args.w: subprocess.Popen("nfsstat -l | grep 'write:' | awk '{print $5}' ",shell=True)
en revanche, si j'utilise l'argument -a par exemple (python myscript.py -a), j'obtiens qu'une stat :
52145
En soit mon script fonctionne, j'obtiens bien le résultat souhaité.
Y a-t'il un autre moyen pour faire ceci ? en ne faisait qu'un seul subprocess ?
Partager