I have a problem with smartctl
Have updated from version 5.4 to the lastest version 6.4.. No change.. Same issue
It works fine when running the command smartctl -H /dev/sda
directly from the command line
But when running the command from a cronjob its not working as it should. Here you can see the cron job settings.. Its running as root
The job is running every 60 sec while testing and the command doesn't return anything. Only the timestamp is written to the file.
But if I press the button "Run now" then the command works?! Very strange!? In the code you can see that the output is written to a file.. The output is empty
Another thing.. When the job is automated only one timestamp is written to the file.. Two timestamps should be written?
function check_dev($dev){
$status_ok = "=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED";
$output = shell_exec('smartctl -H '.$dev);
file_put_contents('/var/www/hdd_out.txt', gmdate("M d Y H:i:s", time())."
".$output, FILE_APPEND);
if(strpos($output, $status_ok) !== false){
echo "$dev OK!
";
return true;
}
else{
echo "$dev ERROR!
";
return false;
}
}
if(check_dev('/dev/sda') && check_dev('/dev/sdb')){
$status = 0;
}
else{
$status = 1;
}
output file
Jun 17 2015 10:17:01
Jun 17 2015 10:18:01
Jun 17 2015 10:19:01
Jun 17 2015 10:20:01
Jun 17 2015 10:21:01
Jun 17 2015 10:22:01
Jun 17 2015 10:23:01
Jun 17 2015 10:24:01
Jun 17 2015 10:25:01
Jun 17 2015 10:26:01
Jun 17 2015 10:27:01
Jun 17 2015 10:28:01
Jun 17 2015 10:29:01
Jun 17 2015 10:29:54 # here I manually pressed "Run now"
smartctl 6.4 2014-09-29 r3990 [x86_64-linux-2.6.32-5-amd64] (local build)
Copyright (C) 2002-14, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
Jun 17 2015 10:29:54 # here I manually pressed "Run now"
smartctl 6.4 2014-09-29 r3990 [x86_64-linux-2.6.32-5-amd64] (local build)
Copyright (C) 2002-14, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
Jun 17 2015 10:30:01
Jun 17 2015 10:31:01
Jun 17 2015 10:32:01
Jun 17 2015 10:33:01