This commit is contained in:
spiritlhl
2024-05-04 12:10:24 +00:00
parent 71cf4bcb47
commit 40b2004a23
2 changed files with 12 additions and 22 deletions

View File

@@ -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]
}
}
}

View File

@@ -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
}
Arch = hi.KernelArch
// 查询虚拟化类型
VmType = hi.VirtualizationSystem