tweak active user count
parent
4748465576
commit
13f9932084
21
main.go
21
main.go
|
@ -22,6 +22,7 @@ import (
|
|||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
@ -291,22 +292,16 @@ func liveUserCount(users []*user) int {
|
|||
}
|
||||
|
||||
func activeUserCount() (int, error) {
|
||||
out, err := exec.Command("who").Output()
|
||||
out, err := exec.Command("sh", "-c", "who | cut -d' ' -f1 | wc -l").Output()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("could not run who: %s", err)
|
||||
return 0, fmt.Errorf("failed to get active user count: %w", err)
|
||||
}
|
||||
count, err := strconv.Atoi(strings.TrimSpace(string(out)))
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("could not parse active user count: %w", err)
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(bytes.NewReader(out))
|
||||
|
||||
activeUsers := map[string]bool{}
|
||||
|
||||
for scanner.Scan() {
|
||||
whoLine := scanner.Text()
|
||||
username := strings.Split(whoLine, " ")[0]
|
||||
activeUsers[username] = true
|
||||
}
|
||||
|
||||
return len(activeUsers), nil
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func getUptime() (string, error) {
|
||||
|
|
Loading…
Reference in New Issue