Skip to content

Commit 58ffa43

Browse files
committed
Handle PATH also for sudo, not just smartctl command
1 parent 56a15db commit 58ffa43

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

check_smart.pl

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

86-
my $sudo_command = '';
87-
my $smart_command = undef;
88-
89-
foreach my $path (@sys_path) {
90-
$sudo_command = "$path/sudo" if ($sudo_command eq '' && -x "$path/sudo");
91-
$smart_command = "$path/smartctl" if (!defined($smart_command) && -x "$path/smartctl");
92-
last if ($sudo_command ne '' && defined($smart_command));
93-
}
94-
95-
if (!defined($smart_command)) {
96-
print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n";
97-
exit $ERRORS{'UNKNOWN'};
98-
}
99-
100-
if ($sudo_command ne '') {
101-
$smart_command = "$sudo_command $smart_command";
102-
}
103-
10486
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);
10587
Getopt::Long::Configure('bundling');
10688
GetOptions(
@@ -136,6 +118,24 @@
136118
exit $ERRORS{'OK'};
137119
}
138120

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+
139139
my ($device, $interface) = qw// // '';
140140
if ($opt_d || $opt_g ) {
141141
unless($opt_i){

0 commit comments

Comments
 (0)