Skip to content

Commit 1217f4c

Browse files
authored
Handle PATH also for sudo, not just smartctl command (#115)
* Handle PATH also for sudo, not just smartctl command
1 parent b057237 commit 1217f4c

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

check_smart.pl

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@
6666
# Jun 12, 2025: Alexander Kanevskiy - Add usbjmicron devices (6.16.0)
6767
# Dec 15, 2025: Florian Sager - Fix evaluating ATA Error Count: 0 as a warning (6.17.0)
6868
# Dec 15, 2025: Philippe Beaumont - Add areca devices (6.17.0)
69+
# Apr 21, 2026: Claudio Kuenzler - Fix sys path for sudo command (6.17.1)
6970

7071
use strict;
7172
use Getopt::Long;
7273
use File::Basename qw(basename);
7374

7475
my $basename = basename($0);
75-
my $revision = '6.17.0';
76+
my $revision = '6.17.1';
7677

7778
# Standard Nagios return codes
7879
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
@@ -117,6 +118,24 @@
117118
exit $ERRORS{'OK'};
118119
}
119120

121+
my $sudo_command = '';
122+
my $smart_command = undef;
123+
124+
foreach my $path (@sys_path) {
125+
$sudo_command = "$path/sudo" if ($sudo_command eq '' && -x "$path/sudo");
126+
$smart_command = "$path/smartctl" if (!defined($smart_command) && -x "$path/smartctl");
127+
last if ($sudo_command ne '' && defined($smart_command));
128+
}
129+
130+
if (!defined($smart_command)) {
131+
print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n";
132+
exit $ERRORS{'UNKNOWN'};
133+
}
134+
135+
if ($sudo_command ne '') {
136+
$smart_command = "$sudo_command $smart_command";
137+
}
138+
120139
my ($device, $interface) = qw// // '';
121140
if ($opt_d || $opt_g ) {
122141
unless($opt_i){
@@ -211,18 +230,6 @@
211230
exit $ERRORS{'UNKNOWN'};
212231
}
213232

214-
my $smart_command = undef;
215-
foreach my $path (@sys_path) {
216-
if (-x "$path/smartctl") {
217-
$smart_command = "sudo $path/smartctl";
218-
last;
219-
}
220-
}
221-
222-
if (!defined($smart_command)) {
223-
print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n";
224-
exit $ERRORS{'UNKNOWN'};
225-
}
226233

227234
my $exit_status = 'OK';
228235
my $exit_status_local = 'OK';

0 commit comments

Comments
 (0)