Hi All,
I am having an issue with ATA errors in my syslog. I haven't solved this issue yet but my immediate issue was finding the drive serial given the ATA number. The syslog didn't have enough info. I ended up putting together bits and pieces of info I found and wrote the following script. Hopefully, this will help someone else in the same situation.
#!/bin/bash
# Ask the user for the ATA number to search for
read -p "Enter the disk ATA number to find: " ata
# Find the device name (e.g., sdd) corresponding to the ATA number
device=$(ls -l /sys/block/sd* | grep $(grep ^$ata$ /sys/class/scsi_host/host*/unique_id | awk -F'/' '{print $5}') | awk -F'/' '{print $NF}')
# Check if a device was found
if [ -z "$device" ]; then
echo "No device found for ATA number $ata"
exit 1
fi
# Find the serial number by searching the /dev/disk/by-id directory
serial=$(ls -l /dev/disk/by-id/ | grep "ata-" | grep "../../$device" | awk -F'ata-' '{print $2}' | awk -F' ->' '{print $1}')
# Check if a serial number was found
if [ -z "$serial" ]; then
echo "No serial number found for device $device"
exit 1
fi
# Output the device name and serial number
echo "Device: $device"
echo "Serial Number: $serial"
It takes the ATA number as input and creates output that looks like this:
root@Storm-Tower:~# ./find_disk_by_ata.sh
Enter the disk ATA number to find: 6
Device: sdf
Serial Number: ST18000NM000J-2TV103_ZR5E11XN
ST18000NM000J-2TV103_ZR5E11XN-part1