zoukankan      html  css  js  c++  java
  • c# 获取linux 磁盘信息



    public DiskInfo LinuxDisk(string path) { DiskInfo disk = new DiskInfo(); if (string.IsNullOrEmpty(path)) { return disk; } if (!path.StartsWith("/")) { path = "/" + path; } string shellPathLine = string.Format("cd {0}", path); string printLine = " awk '{print $2,$3,$4,$5}'"; string shellLine = string.Format("df -k {0} |", path) + printLine; Process p = new Process(); p.StartInfo.FileName = "sh"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); p.StandardInput.WriteLine(shellPathLine); p.StandardInput.WriteLine(shellLine); p.StandardInput.WriteLine("exit"); string strResult = p.StandardOutput.ReadToEnd(); string[] arr = strResult.Split(' '); if (arr.Length == 0) { return disk; } string[] resultArray = arr[1].TrimStart().TrimEnd().Split(' '); if (resultArray == null || resultArray.Length == 0) { return disk; } disk.TotalSize = Convert.ToInt32(resultArray[0]); disk.UsedSize = Convert.ToInt32(resultArray[1]); disk.AvailableSize = Convert.ToInt32(resultArray[2]); disk.Use = resultArray[3]; logger.Info(string.Format("Linux获取目录:{0},总大小:{1},已用:{2},未用:{3},使用率:{4}", path, disk.TotalSize, disk.UsedSize, disk.AvailableSize, disk.Use)); return disk; }
     public class DiskInfo
        {
            public long TotalSize { get; set; }
    
            public long UsedSize { get; set; }
    
            public long AvailableSize { get; set; }
    
            public string Use { get; set; }
        }
  • 相关阅读:
    ML与NLP的2019年度总结与展望
    python在文本开头插入一行的实例
    Git Notes
    warmup 预热学习率
    python error整理
    python 中字符串处理
    集成学习voting Classifier在sklearn中的实现
    机器学习 评价指标整理
    PaddlePaddle Notes
    linux 常用指令 文件操作trick等
  • 原文地址:https://www.cnblogs.com/elsons/p/15340064.html
Copyright © 2011-2022 走看看