2017-07-10 1 views
-2

wie das Skript zu ändern, mich zu warnen, wenn block_usage_pct> 90%Python-Skript-Dateisystem Raum zu überwachen df mit -h

from __future__ import with_statement 
import contextlib 
import os 
import sys 
print "Filesystem\tMounted on\tUse%\tIUse%" 
with contextlib.closing(open('/etc/mtab')) as fp: 
    for m in fp: 
    fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = m.split() 
    if fs_spec.startswith('/'): 
     r = os.statvfs(fs_file) 
     block_usage_pct = 100.0 - (float(r.f_bavail)/float(r.f_blocks) * 100) 
     inode_usage_pct = 100.0 - (float(r.f_favail)/float(r.f_files) * 100) 

, wenn ich versuchen, diese sagt, es synatx ungültig wenn (float (block_usage_pct))> 10 print "% s \ t% s \ t \ t% d %% \ t% d %%" % (fs_spec, fs_file, block_usage_pct, inode_usage_pct)

+0

Stack Overflow ist kein Code-Schreibdienst. Veröffentlichen Sie Ihren Code und sagen Sie, was das spezifische Problem ist. – klutt

Antwort

0

Diese answer ist eine gute Referenz, wie df -h aufzurufen Mit Python können Sie die Ausgabe bearbeiten und die Regeln anwenden, die Sie anwenden möchten.

+0

aus __future__ import with_statement import contextlib import os import sys print "Filesystem \ tMounted auf \ tuse% \ tIUse%" mit contextlib.closing (open (/ etc/mtab ')) als fp: für m in fp: fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = m.split() wenn fs_spec.startswith ('/'): r = os.statvfs (fs_file) block_usage_pct = 100,0 - (float (R .f_bavail)/float (r.f_blocks) * 100) "% s \ t% s \ t \ t% d %% \ t% d %%"% drucken (fs_spec, fs_file, block_usage_pct, inode_usage_pct) ich möchte setup alert wann immer block_usage_pct> 90. – cad

Verwandte Themen