Last active
September 5, 2022 15:43
-
-
Save linuxwizard/8f8af84ba0bffbe6fc7350e78187875b to your computer and use it in GitHub Desktop.
Script for checking disk performance using smartctl, dd and hdparm. Requires CentOS installed :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Date 20/10/2017 , Version 1.0.1 | |
#Authors : Arun D, Nikhil Sasi | |
#Requirements : CentOS installed | |
#Note : Not coded for checking Hardware RAID arrays | |
#Things to do : Log file generation | |
echo -n "SMARTCTL test selection, Enter [short/long]: " | |
read tytest | |
sleep 2 | |
#SCRIPT STARTS | |
echo "=========================================================" | |
#To check if logged in user is root | |
if [ $(id -u) -ne 0 ]; then | |
echo "Run this script as a Root user only" >&2 | |
exit 1 | |
else | |
echo "Root user logged in" | |
fi | |
echo "=========================================================" | |
#Check if smartmontools is installed | |
rpm -q smartmontools | |
exit_status=$? | |
if [ $exit_status -gt 0 ];then | |
echo "Installing Smartmontools" | |
yum -y install smartmontools | |
else | |
echo "SmartMontools already installed." | |
fi | |
echo "=========================================================" | |
#SMARTCTL Checks | |
echo "Initiating SmartCtl check" | |
for i in `lsblk | grep -i disk | awk '{print $1}'` | |
do | |
echo "======/dev/$i=========" | |
smartctl -a /dev/$i|grep -E -A 1 'Device Model' | |
echo " " | |
echo "Terminating any checks started earlier" | |
smartctl -X /dev/$i | grep -A 1 "Abort SMART" | |
echo " " | |
if [ "$tytest" == "short" ];then | |
echo "Initiating short test" | |
smartctl -t short /dev/$i | grep "minutes" | echo "Test for /dev/$i will be completed in `awk '{print $3}'` minutes"; | |
else | |
echo "Initiating long test" | |
smartctl -t long /dev/$i | grep "minutes" | echo "Test for /dev/$i will be completed in `awk '{print $3}'` minutes"; | |
fi | |
done | |
echo "=========================================================" | |
echo " DISK check Status" | |
echo "------------------" | |
## smarttest completion status | |
disk_status=100 | |
while [ $disk_status -gt 0 ] | |
do | |
for i in `lsblk | grep -i disk | awk '{print $1}'` | |
do | |
while [ `smartctl -c /dev/$i |grep "Self-test execution status:"| awk '{print $5}'|sed 's/.$//'` -ge 0 ] | |
do | |
if [ `smartctl -c /dev/$i |grep "Self-test execution status:"| awk '{print $5}'|sed 's/.$//'` -eq 0 ];then | |
echo "Smartctl test completed for /dev/$i" | |
disk_status=0 | |
break; | |
fi | |
if [ `smartctl -c /dev/$i |grep "Self-test execution status:"| awk '{print $5}'|sed 's/.$//'` -gt 0 ];then | |
echo "`smartctl -a /dev/$i|grep -A 1 'Self-test execution status:' | awk 'FNR==2{print $1}'` remaining for /dev/$i" | |
disk_status=100 | |
break; | |
fi | |
done | |
done | |
sleep 60; | |
done | |
echo "Smart Test results" | |
for i in `lsblk | grep -i disk | awk '{print $1}'` | |
do | |
smartctl -a /dev/$i | |
done | |
echo "=========================================================" | |
# HDPARM check for disk READ Speeds | |
echo " HDPARM checks for DISK READ SPEED" | |
for i in `lsblk | grep -i disk | awk '{print $1}'` | |
do | |
echo "Cached Disk test for /dev/$i" | |
hdparm -Tt /dev/$i | grep ' disk reads'| awk '{printf "%7s %7s\n",$11,$12}' | |
echo "Direct Disk test for /dev/$i" | |
hdparm --direct -Tt /dev/$i | grep ' disk reads'| awk '{printf "%7s %7s\n",$11,$12}' | |
done | |
echo "=========================================================" | |
#DD command for disk read speed check | |
echo " DD check for DISK WRITE SPEED" | |
for i in `lsblk | grep -i disk | awk '{print $1}'` | |
do | |
if [ "`df -h | grep "/boot" | awk '{print $1}' | awk -F "/" '{print $3}' | sed -e 's/.$//'`" == "$i" ]; then | |
echo "OS INSTALLED DISK /dev/$i" | |
echo "Test with no parameter" | |
dd if=/dev/zero of=/tmp/test.img bs=1M count=1024 |& awk 'FNR==3{printf "%4s %3s\n",$8,$9}' | |
echo "Test with Direct parameter" | |
dd if=/dev/zero of=/tmp/test.img bs=1M count=1024 oflag=direct |& awk 'FNR==3{printf "%4s %3s\n",$8,$9}' | |
echo "Test with dsync parameter" | |
dd if=/dev/zero of=/tmp/test.img bs=1M count=1024 oflag=dsync |& awk 'FNR==3{printf "%4s %3s\n",$8,$9}' | |
echo "Test with big size file with direct parameter" | |
dd if=/dev/zero of=/tmp/test.img bs=1G count=3 oflag=direct |& awk 'FNR==3{printf "%4s %3s\n",$8,$9}' | |
else | |
echo " Additional Disk /dev/$i" | |
echo "Test with no parameter" | |
dd if=/dev/zero of=/dev/$i bs=1M count=1024 |& awk 'FNR==3{printf "%4s %3s\n",$8,$9}' | |
echo "Test with Direct parameter" | |
dd if=/dev/zero of=/dev/$i bs=1M count=1024 oflag=direct |& awk 'FNR==3{printf "%4s %3s\n",$8,$9}' | |
echo "Test with dsync parameter" | |
dd if=/dev/zero of=/dev/$i bs=1M count=1024 oflag=dsync |& awk 'FNR==3{printf "%4s %3s\n",$8,$9}' | |
echo "Test with big size file with direct parameter" | |
dd if=/dev/zero of=/dev/$i bs=1G count=3 oflag=direct |& awk 'FNR==3{printf "%4s %3s\n",$8,$9}' | |
fi | |
done | |
echo "=========================================================" | |
echo "DISK TESTS COMPLETE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's a self destructive script