Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: HDD in STANDBY mode #82

Open
petersulyok opened this issue Feb 17, 2024 · 2 comments
Open

Feature request: HDD in STANDBY mode #82

petersulyok opened this issue Feb 17, 2024 · 2 comments
Assignees

Comments

@petersulyok
Copy link

Hi,

I'm looking for a solution for a situation when I'm checking the state of a hard disk in STANDBY mode (it spun down) and I don't want to wake it up. The typical smartctl output is the following:

$ sudo smartctl -n standby --all /dev/sda
smartctl 7.3 2022-02-28 r5338 [x86_64-linux-6.5.0-0.deb12.4-amd64] (local build)
Copyright (C) 2002-22, Bruce Allen, Christian Franke, www.smartmontools.org

Device is in STANDBY mode, exit(2)

When I use pySMART in this context I got the following output:

Python 3.12.2 (main, Feb 17 2024, 07:08:59) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pySMART import *
>>> SMARTCTL.sudo=True
>>> SMARTCTL.options=["-n", "standby"]
>>> SMARTCTL.smartctl_path="/usr/sbin/smartctl"
>>> d=Device("sda")
>>> d
<SAT device on /dev/sda mod:None sn:None>

How can I detect in Device() class if the HDD is in STANDBY mode and the rest of the class is empty? In my mind one or more of the following suggestions would help:

  • a new data member in Device() class (e.g. powerState) which can inform the user that the rest of the class is not initialized
  • access to the raw output of the latest smartctl command
  • access to the return code of the latest smartctl command

Any recommendation for this?
Thanks in advance.
Peter

@petersulyok
Copy link
Author

Hi @ralequi,

As a temporary workaround I use this code to detect STANDBY state of a HDD:

    ...
    rv.standby_mode = False
    SMARTCTL.options = []
    SMARTCTL.smartctl_path = smartctl_path

    # If sudo command should be used
    if sudo:
        SMARTCTL.sudo = True
    else:
        SMARTCTL.sudo = False

    # If no check should be applied in standby power mode of an HDD
    if nocheck:
        SMARTCTL.add_options(["-n", "standby"])

    # Check if `smartctl` can be executed.
    output = SMARTCTL.info(self.__path)
    if not output:
        return None

    # Check if the disk is in STANDBY mode
    if "Device is in STANDBY mode" in output[3]:
        rv.standby_mode = True
        return rv

    # Get SMART data from pySMART.
    sd = Device(self.__path)
    ...

Please confirm this approach or suggest a better one. Thanks.

@ralequi
Copy link
Collaborator

ralequi commented Mar 20, 2024

I've forgotten about this issue.

Let me try some scenarios on my lab.

I would like to check if -n standby is a requirement and how to known when it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants