How to identify the device name for a USB socket?

I have a script which backs up files to a removable USB drive. Usually the USB socket that's used for that (the top socket on the back panel) is mapped to /dev/sda, making things easy - I just plug in the drive and run the script. But that's not always the case; sometimes it could be /dev/sdb, and I can't figure out how to identify (programatically) which device it is. This seems like the kind of problem which must get raised regularly, but STFW hasn't produced anything worthwhile. Can anybody please help? Thanks a lot.

Tony.

0

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: How to identify the device name for a USB socket?

If you look in the /etc/udev directory you will find all sorts of instructions on what to do with a disk which is added to the system. One of the files (something to do with persistent disk names) is created by scripts when you first plug in a disk. You can edit that script or any of the other disk-related instructions to give you a convenient name (a symbolic link) like /dev/usb_backup. Otherwise, try /dev/disk/by-id or by-uuid. This should all work fine on kernel 2.6.16 and later (earlier kernels had a less functional udev etc).

Re: How to identify the device name for a USB socket?

Excellent, I'll read up on udev. Thanks a lot!

Tony.

$world=~s/war/peace/g;

Syndicate content