add root check and better info of current disk to check
This commit is contained in:
parent
c2f946f7ed
commit
017449a58b
27
main.go
27
main.go
@ -4,7 +4,9 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -25,19 +27,32 @@ func execSystem(cmd string, args ...string) []byte {
|
||||
return out.Bytes()
|
||||
}
|
||||
|
||||
func isRoot() bool {
|
||||
currentUser, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatalf("[isRoot] Unable to get current user: %s", err)
|
||||
}
|
||||
return currentUser.Username == "root"
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Running smart check on all disks")
|
||||
if !isRoot() {
|
||||
fmt.Println("this program needs root permissions!")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
disks := getDisks()
|
||||
fmt.Printf("Running smart check on all %d disks.\n", len(disks.Blockdevices))
|
||||
for _, blockdevice := range disks.Blockdevices {
|
||||
fmt.Printf("\nChecking /dev/%s\n", blockdevice.Name)
|
||||
|
||||
path := fmt.Sprintf("/dev/%s", blockdevice.Name)
|
||||
|
||||
info := getDiskInfo(path)
|
||||
fmt.Printf("%s %s\n", info.ModelFamily, info.ModelName)
|
||||
|
||||
diskstring := "HDD"
|
||||
if info.RotationRate == 0 {
|
||||
diskstring = "SSD"
|
||||
}
|
||||
fmt.Printf("\nChecking %s /dev/%s - %s %s\n", diskstring, blockdevice.Name, info.ModelFamily, info.ModelName)
|
||||
|
||||
checkSmartAttributes(path, strings.Contains(strings.ToLower(info.ModelName+info.ModelFamily), strings.ToLower("Seagate")), info.RotationRate != 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user