How to do Disk Checkup using Linux script?

How to do Disk Checkup using Linux script?

Here's a simple disk check script for Linux:

#!/bin/bash

# Check disk space
df -h

# Check disk usage for specific directories
du -sh /path/to/directory1
du -sh /path/to/directory2
# Add more directories as needed

# Check disk health using SMART (requires smartmontools package)
smartctl -a /dev/sda
# Replace /dev/sda with the appropriate device for your system

# Check disk read/write performance using hdparm (requires hdparm package)
hdparm -Tt /dev/sda
# Replace /dev/sda with the appropriate device for your system

# Check disk I/O statistics using iostat (requires sysstat package)
iostat

# Check disk read/write errors using dmesg
dmesg | grep -i error

# Check filesystem errors using fsck (may require unmounting the filesystem)
sudo fsck -y /dev/sda1
# Replace /dev/sda1 with the appropriate partition for your system

# Check disk temperature using smartctl (requires smartmontools package)
smartctl -A /dev/sda | grep -i temperature
# Replace /dev/sda with the appropriate device for your system

Save the script in a file, like disk_checkup.sh, and make it executable with the command chmod +x disk_checkup.sh. Then, run the script by typing ./disk_checkup.sh in the terminal.

Keep in mind that some commands might need admin rights (like sudo) or certain packages installed on your system. Change the commands based on your needs and the tools available in your Linux distribution.