Smartmontools, an acronym for ‘S.M.A.R.T monitoring’ tools is a package that is used to control and monitor computer storage systems using S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology) system built into most modern (P)ATA, Serial ATA, SCSI/SAS devices.
It contains 2 utility programs: smartctl and smartd. These utilities give warnings or alerts of disk degradation and failure.
smartmontools can be used in any Unix/Linux based operating systems. It allows us to run various tests to check the health of the HDD or SSD in your system.
Most modern hard drives use S.M.A.R.T. (Self-Monitoring, Analysis, and Reporting Technology) to assess their condition to determine if something is wrong with the device. This allows the user to view the hard drive’s SMART data and take necessary actions to repair or replace the device.
In this article, we will explore smartmontools and retrieve information on the HDDs and SSD in the system. We will also write a python script to parse the output of smartmontools and store the outputs in an excel sheet.
sudo pip3 install pandas sudo apt-get install smartmontools
Once smartmontools has been installed, we can use the terminal or command line to obtain details of the hard drives.
Device information –
To check whether your device supports SMART monitoring and to obtain other information such as device model, capacity, serial number, etc, we use the following command:
sudo smartctl -i /dev/sda
If it is not enabled, the following command enables SMART monitoring:
sudo smartctl -s on /dev/sda
Checking the health of the device
To display the overall health of the disk, we use the following command:
sudo smartctl -H /dev/sda
This displays the status of your hard drive. If it displays any errors, then your hard drive might be experiencing some problems and you should consider backing up your data.
To run a short test :
sudo smartctl --test=short /dev/sda
The goal of the short test is the rapid identification of a defective hard drive. Therefore, the maximum run time for the short test is 2 min.
To run a long test:
sudo smartctl --test=long /dev/sda
Long tests also identify defects but here, there is no time restriction. The test is more thorough.
To check the results of the test:
sudo smartctl -l selftest /dev/sda
An example –
We can use Python to automate this process and generate a report. For this, we shall use Pandas to store the result in excel sheets and the os module to run the commands.
- Python | Create video using multiple images using OpenCV
- Python | Create a stopwatch using clock object in kivy using .kv file
- Image resizing using Seam carving using OpenCV in Python
- Python | Visualizing O(n) using Python
- Python - Read blob object in python using wand library
- Creating and updating PowerPoint Presentations in Python using python - pptx
- Circular (Oval like) button using canvas in kivy (using .kv file)
- Send mail from your Gmail account using Python
- Cartooning an Image using OpenCV - Python
- Using Iterations in Python Effectively
- Generate a graph using Dictionary in Python
- Create a Website Alarm Using Python
- Whatsapp using Python!
- Downloading files from web using Python
- Mouse and keyboard automation using Python
- GET and POST requests using Python
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Twitter Sentiment Analysis using Python
- Formatted text in Linux Terminal using Python
- Determine the type of an image in Python using imghdr