Last active
February 28, 2024 01:18
-
-
Save codingtony/4184451 to your computer and use it in GitHub Desktop.
Bash script to print the serial number of hard disk
This file contains 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/sh | |
# Print the serial number of your disks with this script | |
ls /dev/disk/by-id/ata* | awk -F- '{ if (NF==4) { print $NF} }' | while read SERIAL; | |
do | |
DEVICE=$(readlink -f /dev/disk/by-id/*$SERIAL); | |
echo $DEVICE" "$SERIAL; | |
done | sort; |
This file contains 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 | |
# Network version of the serial script | |
# provide the list of hostnames in parameter | |
for host in $@ | |
do | |
ssh ${host} "ls /dev/disk/by-id/ata* | grep -v part | xargs -n1 -I % bash -c '{ | |
SERIAL=\$(basename % | cut -d- -f2-3); | |
DEVICE=\$(readlink -f %); | |
MOUNT=\$(mount | grep \${DEVICE} | cut -d\" \" -f3); | |
echo \"\$(hostname) \${DEVICE} \${SERIAL} \${MOUNT}\"; | |
}'" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment