mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-19 00:18:20 +02:00
Update check-smart-devices.ps1
This commit is contained in:
parent
6587c05642
commit
28833ae2a8
@ -36,6 +36,11 @@ if ($lastExitCode -ne "0") { $Healthy = 0 }
|
|||||||
& "$PSScriptRoot/check-ping.ps1"
|
& "$PSScriptRoot/check-ping.ps1"
|
||||||
if ($lastExitCode -ne "0") { $Healthy = 0 }
|
if ($lastExitCode -ne "0") { $Healthy = 0 }
|
||||||
|
|
||||||
|
if ($IsLinux) {
|
||||||
|
& "$PSScriptRoot/check-smart-devices.ps1"
|
||||||
|
if ($lastExitCode -ne "0") { $Healthy = 0 }
|
||||||
|
}
|
||||||
|
|
||||||
if ($Healthy) {
|
if ($Healthy) {
|
||||||
"✔️ $Hostname is healthy"
|
"✔️ $Hostname is healthy"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
check-smart-devices.ps1
|
check-smart-devices.ps1 [<type>]
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Performs a short selftest on your S.M.A.R.T. HDD/SSD devices.
|
Performs a selftest on your S.M.A.R.T. HDD/SSD devices. Type is either short(default) or long.
|
||||||
Requires smartctl (smartmontools) and admin rights.
|
Requires smartctl (smartmontools) and admin rights.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./check-smart-devices
|
PS> ./check-smart-devices
|
||||||
|
✔️ short selftest started on S.M.A.R.T. device /dev/sda
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz · License: CC0
|
Author: Markus Fleschutz · License: CC0
|
||||||
.LINK
|
.LINK
|
||||||
@ -14,22 +15,19 @@
|
|||||||
|
|
||||||
#Requires -RunAsAdministrator
|
#Requires -RunAsAdministrator
|
||||||
|
|
||||||
|
param([string]$type = "short")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
"Step 1/4: Checking for 'smartctl'..."
|
|
||||||
$Result=(smartctl --version)
|
$Result=(smartctl --version)
|
||||||
if ($lastExitCode -ne "0") { throw "Can't execute 'smartctl' - make sure smartmontools are installed" }
|
if ($lastExitCode -ne "0") { throw "Can't execute 'smartctl' - make sure smartmontools are installed" }
|
||||||
|
|
||||||
"Step 2/4: Scanning for S.M.A.R.T. devices..."
|
|
||||||
$Devices = $(sudo smartctl --scan-open)
|
$Devices = $(sudo smartctl --scan-open)
|
||||||
|
|
||||||
foreach($Device in $Devices) {
|
foreach($Device in $Devices) {
|
||||||
$Array = $Device.split(" ")
|
$Array = $Device.split(" ")
|
||||||
$Device = $Array[0]
|
$Device = $Array[0]
|
||||||
"Step 3/4: Starting short selftest on device $Device..."
|
$Result = (sudo smartctl --test=$type $Device)
|
||||||
& sudo smartctl --test=short $Device
|
"✔️ $type selftest started on S.M.A.R.T. device $Device"
|
||||||
}
|
}
|
||||||
|
|
||||||
"✔️ Done."
|
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||||
|
Loading…
Reference in New Issue
Block a user