-
Notifications
You must be signed in to change notification settings - Fork 30
/
machine.go
50 lines (46 loc) · 1.03 KB
/
machine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package system
import (
"fmt"
"strconv"
"strings"
)
//机型
func MachineProductName(args string) string {
cmd := "dmidecode | grep 'Product Name' | uniq 2>/dev/null"
output, err := Exec(cmd)
if err != nil {
return ""
}
if output == "" {
return ""
}
lines := strings.Split(output, "\n")
models := []string{}
for _, line := range lines {
if strings.Contains(line, "Product Name:") {
model := strings.Replace(line, "Product Name:", "", -1)
model = strings.TrimSpace(model)
models = append(models, model)
}
}
ret := strings.Join(models, "|")
return ret
}
//操作系统版本
func OsVersion(args string) string {
return ExecOutput("uname -sr")
}
//已运行时间(天)
func UpTime(args string) string {
content, err := GetFileContent("/proc/uptime")
if err != nil {
return ""
}
strList := strings.Fields(content)
upSeconds, err := strconv.ParseFloat(strList[0], 64)
if err != nil {
return ""
}
days := upSeconds / 3600 / 24
return fmt.Sprintf("%.0f", days)
}