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; }
        }
  • 相关阅读:
    怎样从外网访问内网Django?
    怎样从外网访问内网Jboss?
    怎样从外网访问内网php-fpm?
    python中关于发邮件的示例
    python中关于局部变量与全局变量的认识
    python实现二分查找与冒泡排序
    自动化测试框架中关于selenium api的二次封装
    python 的日志相关应用
    python中关于字符串的操作
    EBS 物料单位换算
  • 原文地址:https://www.cnblogs.com/elsons/p/15340064.html
Copyright © 2011-2022 走看看