If lsblk -o NAME,SERIAL,MOUNTPOINT
includes the following in its output
sdb X55MM4827123
└─sdb1
└─luks-4d0dc651-9aa6-452d-9442-7b33d95f8427 /run/media/main/mydrive
What is a simple console/CLI command I can use to get the serial number (X55MM4827123
in this case) when I provide the mountpoint (/run/media/main/mydrive
in this case)?
The answer doesn't necessarily have to use lsblk
, but it should hopefully be concise and ideally use just simple bash scripting.
Best Answer
As far as I understand, the goal is to give the command input as mountpoint and output serial number. Well, it's possible with a small script that uses a little bit of
awk
magic andsmartmontools
package.Demo2:
And here's script itself:
Since you do get serial number in
lsblk
, and GNU version1 oflsblk
can output JSON data, I've put together a Python script that works as so2:1. I've no idea if non-GNU versions of
lsblk
exist, but if they do - leave a comment2. Serial numbers shown are random strings generated from
/dev/urandom
for demo purposes