1
cat /proc/scsi/usb-storage/27 
------------------
   Host scsi27: usb-storage
       Vendor: SanDisk
      Product: Cruzer Blade
Serial Number: 4C530000230331109030
     Protocol: Transparent SCSI
    Transport: Bulk
       Quirks: SANE_SENSE

because it keeps on changing the hostscsi number whenever the pendrive is inserted

3 Answers 3

4

Using lsblk:

$ lsblk --output KNAME,SERIAL /dev/sdb
KNAME SERIAL
sdb   4CEDFB6D543AF360199308B2

I test twice with the same device, always got the same serial.

0

I use the smartctl tool:

# smartctl /dev/sda -i | grep Serial
Serial Number:    S1D3LYBG290266

I prefer it over lsblk simply because the former is more human read-able but if you need it in a bash script this is worthless;

0

After a lot of search, I have come with an better script, it might be useful for others also. This will display only removable devices like pendrive, etc. This script will work for all users in my centos7

#!/bin/bash
for C in `ls /sys/block/`; do 
    RE=`cat /sys/block/$C/removable`
        if [ $RE == "1" ] ;then 
            #VENDOR=`/bin/udevadm info --name=/dev/$C | grep ID_VENDOR=|awk -F"=" ' { print $2}'`
            #MODEL=`/bin/udevadm info --name=/dev/$C | grep ID_MODEL=|awk -F"=" ' { print $2}'`
            #SERIAL=`/bin/udevadm info --name=/dev/$C | grep SERIAL_SHORT|awk -F"=" ' { print $2}'`
            #echo $VENDOR-$MODEL"-"$SERIAL #print as per your taste
            USB_SERIAL=`/bin/udevadm info --name=/dev/$C | grep ID_SERIAL=|awk -F"=" ' { print $2}'|awk -F"-" ' { print $1}'`
            echo  $USB_SERIAL #or just the default one
        fi 
done

JetFlash_Transcend_4GB_08XHIHH4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .