tweak active user count

trunk
vilmibm 2020-06-18 20:14:49 +00:00
parent 4748465576
commit 13f9932084
1 changed files with 8 additions and 13 deletions

21
main.go
View File

@ -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) {