Skip to content

Instantly share code, notes, and snippets.

@codingtony
Last active February 28, 2024 01:18
Show Gist options
  • Save codingtony/4184451 to your computer and use it in GitHub Desktop.
Save codingtony/4184451 to your computer and use it in GitHub Desktop.
Bash script to print the serial number of hard disk
#!/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;
!/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