From cf9593b706021d828f69369750bf0da5761bbc92 Mon Sep 17 00:00:00 2001 From: Napsty Date: Tue, 21 Apr 2026 08:10:58 +0200 Subject: [PATCH 1/3] Handle PATH also for sudo, not just smartctl command --- check_smart.pl | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/check_smart.pl b/check_smart.pl index bd8fd62..1a77060 100755 --- a/check_smart.pl +++ b/check_smart.pl @@ -82,6 +82,24 @@ $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; +my $sudo_command = ''; +my $smart_command = undef; + +foreach my $path (@sys_path) { + $sudo_command = "$path/sudo" if ($sudo_command eq '' && -x "$path/sudo"); + $smart_command = "$path/smartctl" if (!defined($smart_command) && -x "$path/smartctl"); + last if ($sudo_command ne '' && defined($smart_command)); +} + +if (!defined($smart_command)) { + print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n"; + exit $ERRORS{'UNKNOWN'}; +} + +if ($sudo_command ne '') { + $smart_command = "$sudo_command $smart_command"; +} + 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); Getopt::Long::Configure('bundling'); GetOptions( @@ -211,18 +229,6 @@ exit $ERRORS{'UNKNOWN'}; } -my $smart_command = undef; -foreach my $path (@sys_path) { - if (-x "$path/smartctl") { - $smart_command = "sudo $path/smartctl"; - last; - } -} - -if (!defined($smart_command)) { - print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n"; - exit $ERRORS{'UNKNOWN'}; -} my $exit_status = 'OK'; my $exit_status_local = 'OK'; From 56a15db79531f9af5ab96e187bb8835af39581d0 Mon Sep 17 00:00:00 2001 From: Napsty Date: Tue, 21 Apr 2026 08:13:59 +0200 Subject: [PATCH 2/3] Handle PATH also for sudo, not just smartctl command --- check_smart.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/check_smart.pl b/check_smart.pl index 1a77060..bdc9fa7 100755 --- a/check_smart.pl +++ b/check_smart.pl @@ -66,13 +66,14 @@ # Jun 12, 2025: Alexander Kanevskiy - Add usbjmicron devices (6.16.0) # Dec 15, 2025: Florian Sager - Fix evaluating ATA Error Count: 0 as a warning (6.17.0) # Dec 15, 2025: Philippe Beaumont - Add areca devices (6.17.0) +# Apr 21, 2026: Claudio Kuenzler - Fix sys path for sudo command (6.17.1) use strict; use Getopt::Long; use File::Basename qw(basename); my $basename = basename($0); -my $revision = '6.17.0'; +my $revision = '6.17.1'; # Standard Nagios return codes my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); From 58ffa4323397b573957836975e45cc358db8a628 Mon Sep 17 00:00:00 2001 From: Napsty Date: Tue, 21 Apr 2026 08:17:23 +0200 Subject: [PATCH 3/3] Handle PATH also for sudo, not just smartctl command --- check_smart.pl | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/check_smart.pl b/check_smart.pl index bdc9fa7..e14a283 100755 --- a/check_smart.pl +++ b/check_smart.pl @@ -83,24 +83,6 @@ $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; -my $sudo_command = ''; -my $smart_command = undef; - -foreach my $path (@sys_path) { - $sudo_command = "$path/sudo" if ($sudo_command eq '' && -x "$path/sudo"); - $smart_command = "$path/smartctl" if (!defined($smart_command) && -x "$path/smartctl"); - last if ($sudo_command ne '' && defined($smart_command)); -} - -if (!defined($smart_command)) { - print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n"; - exit $ERRORS{'UNKNOWN'}; -} - -if ($sudo_command ne '') { - $smart_command = "$sudo_command $smart_command"; -} - 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); Getopt::Long::Configure('bundling'); GetOptions( @@ -136,6 +118,24 @@ exit $ERRORS{'OK'}; } +my $sudo_command = ''; +my $smart_command = undef; + +foreach my $path (@sys_path) { + $sudo_command = "$path/sudo" if ($sudo_command eq '' && -x "$path/sudo"); + $smart_command = "$path/smartctl" if (!defined($smart_command) && -x "$path/smartctl"); + last if ($sudo_command ne '' && defined($smart_command)); +} + +if (!defined($smart_command)) { + print "UNKNOWN - Could not find executable smartctl in " . join(", ", @sys_path) . "\n"; + exit $ERRORS{'UNKNOWN'}; +} + +if ($sudo_command ne '') { + $smart_command = "$sudo_command $smart_command"; +} + my ($device, $interface) = qw// // ''; if ($opt_d || $opt_g ) { unless($opt_i){