hi,
I am trying to write a bash shell script to detect USB devices (hard drives) on my Debian Lenny system. This is how I am trying to detect USB devices:
Code:
#!/bin/bash
echo "Finding USB devices. Please wait..."
find /dev/disk/by-path/ -type l -iname \*usb\*scsi\* -print0|xargs -0 -iD readlink -f D
exit 0
The output of the above "find" commands gives me something like this:
Code:
/dev/sda1
/dev/sda5
/dev/sda2
/dev/sda
/dev/sdb5
/dev/sdb2
/dev/sdb1
/dev/sdb
I would like to achieve the following two things:
1. I just want:
from the above output to be stored in two variables say:
Code:
USB_DEVICE_1 = /dev/sda
USB_DEVICE_2 = /dev/sdb
2. Also this process should be dynamic. For example, if there are 3 USB devices instead of the two (like above) then my shell script should store something like this:
Code:
USB_DEVICE_1 = /dev/sda
USB_DEVICE_2 = /dev/sdb
USB_DEVICE_3 = /dev/sdc
For just 1 USB device attached to the system:
Code:
USB_DEVICE_1 = /dev/sda
I am assuming some kind of "for" loop will be required but I am not sure how to do that.
Thanks