Skip to content

Conversation

cristian-caloghera
Copy link
Contributor

Allow execution of smartctl even if it is installed in an unexpected (for Linux) path.

Some OS, (e.g.: FreeBSD) do not install smartctl under the usr/sbin/ path, but instead use another path like /usr/local/sbin/.
This commit makes use of the which command to locate the smartctl in the PATH and execute from there. As such it does not make any assumption where smartctl is installed, improving portability.

@dswarbrick
Copy link
Member

According to the manpage for which, it works "by searching the PATH for executable files matching the names of the arguments."

In other words, this could be accomplished by omitting the which stuff altogether, and simply using a non-qualified smartctl command, i.e. relying on the inherent functionality of the shell's PATH to find the command.

@cristian-caloghera
Copy link
Contributor Author

cristian-caloghera commented May 17, 2025

You are correct. No idea why it did not occur to me initially, but I have changed the code to call smartctl directly, i.e. without an absolute path.

There's one possible caveat to this that I think of, if executing the script form from a cronjob, the PATH variable is not necessarily the same one as the user might expect. So, this change might break cronjobs that were initially running. On the other hand, I think the user is then responsible to configure the environment of cronjob such that all needed commands can be found.

@dswarbrick dswarbrick merged commit 4242258 into prometheus-community:master Jul 15, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants