more good GetAge

This commit is contained in:
nekohepott 2026-06-17 04:16:28 +03:00
parent 1c185ff075
commit 8f8e6ffdc8
No known key found for this signature in database

View File

@ -9,6 +9,7 @@ import (
"regexp"
"strconv"
"strings"
"syscall"
"time"
)
@ -236,16 +237,21 @@ func GetShell() string {
}
func GetAge() string {
out, err := exec.Command("stat", "-c", "%W", "/").Output()
info, err := os.Stat("/etc/machine-id")
if err != nil {
info, err = os.Stat("/")
if err != nil {
return "unknown"
}
birthTime := strings.TrimSpace(string(out))
if birthTime == "0" || birthTime == "-" {
}
stat, ok := info.Sys().(*syscall.Stat_t)
if !ok {
return "unknown"
}
age, _ := strconv.Atoi(birthTime)
age = int(time.Now().Unix() - int64(age))
birth := age / 86400
return fmt.Sprintf("%d days", birth)
birthTime := time.Unix(stat.Ctim.Sec, stat.Ctim.Nsec)
days := int(time.Since(birthTime).Hours() / 24)
return fmt.Sprintf("%d days", days)
}