Skip to content

Commit cf9593b

Browse files
committed
Handle PATH also for sudo, not just smartctl command
1 parent b057237 commit cf9593b

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

check_smart.pl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@
8282
$ENV{'BASH_ENV'}='';
8383
$ENV{'ENV'}='';
8484

85+
my $sudo_command = '';
86+
my $smart_command = undef;
87+
88+
foreach my $path (@sys_path) {
89+
$sudo_command = "$path/sudo" if ($sudo_command eq '' && -x "$path/sudo");
90+
$smart_command = "$path/smartctl" if (!defined($smart_command) && -x "$path/smartctl");
91+
last if ($sudo_command ne '' && defined($smart_command));
92+
}
93+
94+
if (!defined($smart_command)) {
95+
print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n";
96+
exit $ERRORS{'UNKNOWN'};
97+
}
98+
99+
if ($sudo_command ne '') {
100+
$smart_command = "$sudo_command $smart_command";
101+
}
102+
85103
use vars qw($opt_b $opt_d $opt_g $opt_debug $opt_h $opt_i $opt_e $opt_E $opt_o $opt_r $opt_s $opt_v $opt_w $opt_q $opt_l $opt_skip_sa $opt_skip_temp $opt_skip_load_cycles $opt_skip_error_log $opt_hide_sn);
86104
Getopt::Long::Configure('bundling');
87105
GetOptions(
@@ -211,18 +229,6 @@
211229
exit $ERRORS{'UNKNOWN'};
212230
}
213231

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-
}
226232

227233
my $exit_status = 'OK';
228234
my $exit_status_local = 'OK';

0 commit comments

Comments
 (0)