From 40b2004a235ca7eade9448dfc6c42b92a31941cc Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Sat, 4 May 2024 12:10:24 +0000 Subject: [PATCH] update --- system/disk.go | 22 ++++++++-------------- system/host.go | 12 ++++-------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/system/disk.go b/system/disk.go index 68089a0..f589cfe 100644 --- a/system/disk.go +++ b/system/disk.go @@ -46,23 +46,17 @@ func getDiskInfo() (string, string, string, error) { } } } else { + // df -x tmpfs / | awk "NR>1" | sed ":a;N;s/\\n//g;ta" | awk '{print $1}' cmd := exec.Command("df", "-x", "tmpfs", "/") output, err := cmd.Output() if err == nil { - awkCmd := exec.Command("awk", "NR>1") - awkCmd.Stdin = strings.NewReader(string(output)) - awkOutput, err := awkCmd.Output() - if err == nil { - sedCmd := exec.Command("sed", ":a;N;s/\\n//g;ta") - sedCmd.Stdin = strings.NewReader(string(awkOutput)) - sedOutput, err := sedCmd.Output() - if err != nil { - finalAwkCmd := exec.Command("awk", "{print $1}") - finalAwkCmd.Stdin = strings.NewReader(string(sedOutput)) - finalOutput, err := finalAwkCmd.Output() - if err != nil { - bootPath = string(finalOutput) - } + // 解析输出 + lines := strings.Split(string(output), "\n") + if len(lines) >= 2 { + // 解析第二行的值 + fields := strings.Fields(lines[1]) + if len(fields) < 6 { + bootPath = fields[0] } } } diff --git a/system/host.go b/system/host.go index 436fc69..3a33ba8 100644 --- a/system/host.go +++ b/system/host.go @@ -3,11 +3,12 @@ package system import ( "context" "fmt" + "runtime" + "time" + "github.com/libp2p/go-nat" "github.com/oneclickvirt/basics/system/utils" "github.com/shirou/gopsutil/host" - "runtime" - "time" ) func getHostInfo() (string, string, string, string, string, string, string, string, error) { @@ -22,12 +23,7 @@ func getHostInfo() (string, string, string, string, string, string, string, stri } else { cpuType = "Physical" } - if runtime.GOOS == "linux" { - Platform = hi.Platform - Kernal = hi.PlatformVersion - } else { - Platform = hi.Platform + " " + hi.PlatformVersion - } + Platform = hi.Platform + " " + hi.PlatformVersion Arch = hi.KernelArch // 查询虚拟化类型 VmType = hi.VirtualizationSystem