python BrickstorOS片段用于获取各种文件系统信息。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python BrickstorOS片段用于获取各种文件系统信息。相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
# Copyright 2016 RackTop Systems Inc. and/or its affiliates.
# http://www.racktopsystems.com
#
# The methods and techniques utilized herein are considered TRADE SECRETS
# and/or CONFIDENTIAL unless otherwise noted. REPRODUCTION or DISTRIBUTION
# is FORBIDDEN, in whole and/or in part, except by express written permission
# of RackTop Systems.
import sys, os
import json

if len(sys.argv) < 2:  # Must give starting point, i.e. /storage/p01/foo/bar
    sys.stderr.write("Path to root of tree to scan is required!\n")
    sys.exit(1)

obj = {}

def stat_to_json(f):
    fi = os.stat(f)
    return \
    {
        "path": f,
        "mode": fi.st_mode,
        "inonde": fi.st_ino,
        "gid": fi.st_gid,
        "uid": fi.st_uid,
        "size": fi.st_size,
        "atime": fi.st_atime,
        "mtime": fi.st_mtime,
        "ctime": fi.st_ctime,
    }

for root, dirs, files in os.walk(sys.argv[1], topdown=True):
    f = [stat_to_json("%s/%s" % (root, _)) for _ in files]
    obj.update(
        {
            root: f,
        }
    )
print(json.dumps(obj))

以上是关于python BrickstorOS片段用于获取各种文件系统信息。的主要内容,如果未能解决你的问题,请参考以下文章

sh BrickStorOS配置调整脚本

sh BrickstorOS的容量,使用和配额

sh BrickstorOS过程信息

sh 控制BrickstorOS上的活动核心

sh BrickstorOS安装程序

sh BrickStorOS基本健康和系统信息收集脚本