44 lines
834 B
Go
44 lines
834 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func execSystem(cmd string, args ...string) []byte {
|
|
com := exec.Command(cmd, args...)
|
|
var out bytes.Buffer
|
|
com.Stdout = &out
|
|
com.Stderr = &out
|
|
|
|
err := com.Run()
|
|
|
|
if out.Bytes() == nil {
|
|
fmt.Println(out.String())
|
|
log.Fatal(err)
|
|
return nil
|
|
}
|
|
|
|
return out.Bytes()
|
|
}
|
|
|
|
func main() {
|
|
fmt.Println("Running smart check on all disks")
|
|
|
|
disks := getDisks()
|
|
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)
|
|
|
|
checkSmartAttributes(path, strings.Contains(strings.ToLower(info.ModelName+info.ModelFamily), strings.ToLower("Seagate")), info.RotationRate != 0)
|
|
}
|
|
|
|
}
|