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; }
        }
  • 相关阅读:
    判断php变量是否定义,是否为空
    HTTP Client 编写
    推荐《冒号课堂——编程范式与OOP思想》
    一些免费的HTML编辑器
    如何判断mysql中数据表中两个列之间的相同记录和不同记录
    PostgreSQL 8.4, SQL Server 2008, MySQL 5.1比较
    JDBC纵览
    使用jdbc连接sql数据库
    关于PHP中变量的判定
    如何判断数据库中是否存在一个数据表
  • 原文地址:https://www.cnblogs.com/elsons/p/15340064.html
Copyright © 2011-2022 走看看