This commit is contained in:
mike 2020-01-02 22:53:48 -08:00
parent 98ee8b8de4
commit f3dfb138ad

View File

@ -5,12 +5,14 @@
// Change directory to here // Change directory to here
$thisDir=DirName(__FILE__); $thisDir=DirName(__FILE__);
// Make sure we're root // Make sure we're root
$whoami=Trim(Shell_Exec("whoami")); $whoami=Trim(Shell_Exec("whoami"));
if($whoami!='root'){ if($whoami!='root'){
die("Please run as root (Currently: $whoami)"); die("Please run as root (Currently: $whoami)");
} }
// First parameter should be path to config file // First parameter should be path to config file
$config_path=$argv[1]; $config_path=$argv[1];
if(!File_Exists($config_path)){ if(!File_Exists($config_path)){
@ -19,7 +21,8 @@ if(!File_Exists($config_path)){
if(!Is_File($config_path)){ if(!Is_File($config_path)){
die("\nConfig file ... isn't a file?: {$config_path}\n"); die("\nConfig file ... isn't a file?: {$config_path}\n");
} }
$config_path=RealPath($config_path); $config_path = RealPath($config_path);
// Second could be a test type (optional) // Second could be a test type (optional)
$bStartTests_short=false; $bStartTests_short=false;
@ -36,11 +39,13 @@ if(IsSet($argv[2])){
} }
} }
// Load config // Load config
$config=LoadConfig($config_path); $config = LoadConfig($config_path);
// Show information about each drive // Show information about each drive
foreach($config['devices'] as $name=>$device){ foreach ($config['devices'] as $name=>$device ) {
// //
$match=true; $match=true;
@ -74,13 +79,14 @@ foreach($config['devices'] as $name=>$device){
// Ask smartctl for status // Ask smartctl for status
$command="smartctl --all --device {$device_safe} {$path_safe}"; $command="smartctl --all --device {$device_safe} {$path_safe}";
print "\nCOMMAND: {$command}";
$output_lines=false; $output_lines=false;
Exec($command,$output_lines,$smart_return_code); Exec($command,$output_lines,$smart_return_code);
$lines=Implode("\n",$output_lines); $lines=Implode("\n",$output_lines);
// Output any messages indicated by smartctl // Output any messages indicated by smartctl
$messages=CheckNamedBits($smart_return_code); $messages = CheckNamedBits($smart_return_code);
foreach($messages as $message){ foreach ($messages as $message) {
print "\nMESSAGE: {$message}"; print "\nMESSAGE: {$message}";
} }
@ -188,14 +194,14 @@ function CheckNamedBits($return_code)
// //
$map=Array( $map=Array(
'0'=>"Command line did not parse.", '0' => "Command line did not parse.",
'1'=>"Device open failed, device did not return an IDENTIFY DEVICE structure, or device is in a low-power mode", '1' => "Device open failed, device did not return an IDENTIFY DEVICE structure, or device is in a low-power mode",
'2'=>"Some SMART or other ATA command to the disk failed, or there was a checksum error in a SMART data structure", '2' => "Some SMART or other ATA command to the disk failed, or there was a checksum error in a SMART data structure",
'3'=>"SMART status check returned \"DISK FAILING\".", '3' => "SMART status check returned \"DISK FAILING\".",
'4'=>"We found prefail Attributes <= threshold.", '4' => "We found prefail Attributes <= threshold.",
'5'=>"SMART status check returned \"DISK OK\" but we found that some (usage or prefail) Attributes have been <= threshold at some time in the past.", '5' => "SMART status check returned \"DISK OK\" but we found that some (usage or prefail) Attributes have been <= threshold at some time in the past.",
'6'=>"The device error log contains records of errors.", '6' => "The device error log contains records of errors.",
'7'=>"The device self-test log contains records of errors. [ATA only] Failed self-tests outdated by a newer successful extended self-test are ignored." '7' => "The device self-test log contains records of errors. [ATA only] Failed self-tests outdated by a newer successful extended self-test are ignored."
); );
// //
@ -209,10 +215,10 @@ function CheckNamedBits($return_code)
} }
// //
function CheckBitPosition($toCheck,$index) function CheckBitPosition($toCheck, $index)
{ {
// //
$value=Pow(2,$index); $value=Pow(2, $index);
// //
$bIsSet=false; $bIsSet=false;