Sponsored Content
Top Forums Shell Programming and Scripting BASH Script to Detect and List USB Flash Drives Post 302297958 by fpmurphy on Monday 16th of March 2009 09:39:26 AM
Old 03-16-2009
Another way to do what you want is to query the devices using the hal-* utilities which are available on most modern GNU/Linux distributions.
Code:
#!/bin/ksh93

for udi in $(/usr/bin/hal-find-by-capability --capability storage)
do
    device=$(hal-get-property --udi $udi --key block.device)
    vendor=$(hal-get-property --udi $udi --key storage.vendor)
    model=$(hal-get-property --udi $udi --key storage.model)
    if [[ $(hal-get-property --udi $udi --key storage.bus) = "usb" ]]
    then
        parent_udi=$(hal-find-by-property --key block.storage_device --string $udi)
        mount=$(hal-get-property --udi $parent_udi --key volume.mount_point)
        label=$(hal-get-property --udi $parent_udi --key volume.label)
        media_size=$(hal-get-property --udi $udi --key storage.removable.media_size)
        size=$(( ceil(media_size/(1000*1000*1000)) ))
        printf "$vendor  $model  $device  $mount  $label "${size}GB" \n"
    fi
done

Here is the output for two USB thumb drives
Code:
$ ./listusb   
Kingston  DataTraveler 2.0  /dev/sdd  /media/KINGSTON  KINGSTON 1GB 
Kingston  DataTraveler 2.0  /dev/sdc  /media/USB-4GB  USB-4GB 4GB

 

9 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

Mounting USB Drives in Solaris 9 x86

I'm trying to moun my external USB Mass Storage Drive (80GB) in my Solaris 9 box, I am new to Solaris, and kind of new to linux / unix variants. The external HD contains windows files, but I will be using it as a central storage area for my windows/ linux clients. Thanks -- N:confused:C (1 Reply)
Discussion started by: N0C717
1 Replies

2. What is on Your Mind?

USB Thumb Drives

I'm hunting around for thumb drives that aren't working. Something you may have kicking around in a drawer that you don't need any more. One you've upgraded and just don't need. I'm willing to pay a couple bucks for you to drop it into an envelope with a few stamps and send it along. I'm... (0 Replies)
Discussion started by: BOFH
0 Replies

3. Shell Programming and Scripting

how floppy disks, CDs and flash drives (pen drives) are accessed in UNIX

hi how floppy disks, CDs and flash drives (pen drives) are accessed in UNIX? thanks (0 Replies)
Discussion started by: nokia1100
0 Replies

4. Filesystems, Disks and Memory

USB Flash Drives

Can Solaris/any GNU/Linux distros/ any flavor of FreeBSD be booted, right from aUSB flash drive? Mine's the one pictured here. SanDisk | Products | USB Flash Drives | SanDisk CruzerŽ Titanium Plus USB Flash Drive Also, on a completely unrelated note (just so I don't have to fill up forum... (4 Replies)
Discussion started by: led3234
4 Replies

5. Solaris

Does Solaris Volume Manager support USB flash drives?

I would like to mirror or stripe across multiple USB flash drives on a Sun Blade 100 workstation running Solaris 10. Thanks! (6 Replies)
Discussion started by: yoda9999
6 Replies

6. Shell Programming and Scripting

script to detect a file from inserted usb and puts into a Variable

There is a same named log file that I have on my 2 different android phones. When I plug it into my computer, it appears in the media folder, For example the first android phone: /media/F6BA-0AF5/folder/A.log I want to put that into a variable to be manipulated.... (3 Replies)
Discussion started by: tobenguyen
3 Replies

7. What is on Your Mind?

Idea: selling Puppy Linux flash drives

What do you think of the idea of selling flash drives already prepared to boot Puppy Linux on PCs? (I still need to see if I can boot on Macs using online instructions I've found.) I know it's not too hard to prep your own flash drive, even if you have to buy one first, but just think about why... (8 Replies)
Discussion started by: MrMormon
8 Replies

8. Shell Programming and Scripting

Bash script to detect nonpingable hosts

I have a script to detect if a host is pingable or not. The problem is that I would like it to put the nonpingable hosts in one file and the pingable hosts in another. I have come up with this so far: for ip in `cat /tmp/testlist2`; do ping -c 3 $ip >/dev/null && echo "$ip is up" || echo "$ip... (5 Replies)
Discussion started by: newbie2010
5 Replies

9. Solaris

Anyway to do ufsdump os backup to usb drives

hi folks happy new year to all, I haven't been coming round for a long time. I've been googling about this can't seem to find any good examples, I need to know if it's possible to do a ufsdump os backup into a usb flash drive. Then what about in event of os recovery when we boot to single... (2 Replies)
Discussion started by: sparcguy
2 Replies
UMASS(4)                                                   BSD Kernel Interfaces Manual                                                   UMASS(4)

NAME
umass -- USB Mass Storage Devices driver SYNOPSIS
To compile this driver into the kernel, place the following line in your kernel configuration file: device scbus device usb device umass Alternatively, to load the driver as a module at boot time, place the following line in loader.conf(5): umass_load="YES" DESCRIPTION
The umass driver provides support for Mass Storage devices that attach to the USB port. To use the umass driver, usb(4) and one of uhci(4) or ohci(4) must be configured in the kernel. Additionally, since umass uses the SCSI sub- system and sometimes acts as a SCSI device, it requires da(4) and scbus(4) to be included in the kernel. HARDWARE
The umass driver supports USB Mass Storage devices, including: o ADTEC Stick Drive AD-UST32M, 64M, 128M, 256M o Denno FireWire/USB2 Removable 2.5-inch HDD Case MIFU-25CB20 o FujiFilm Zip USB Drive ZDR100 USB A o GREEN HOUSE USB Flash Memory "PicoDrive" GH-UFD32M, 64M, 128M o Huawei Mobile (SD slot) o IBM 32MB USB Memory Key (P/N 22P5296) o IBM 256MB USB Drive (MSYSTEM DiskOnKey2) o IBM ThinkPad USB Portable CD-ROM Drive (P/N 33L5151) o I-O DATA USB CD/CD-R/CD-RW/DVD-R/DVD-RW/DVD-RAM/DVD-ROM Drive DVR-iUH2 (CDROM, DVD-RAM only) o I-O DATA USB x6 CD-RW Drive CDRW-i64/USB (CDROM only) o I-O DATA USB/IEEE1394 Portable HD Drive HDP-i30P/CI, HDP-i40P/CI o Iomega USB Zip 100/250 drive o Iomega Zip750 USB2.0 drive o Keian USB1.1/2.0 3.5-inch HDD Case KU350A o Kurouto Shikou USB 2.5-inch HDD Case GAWAP2.5PS-USB2.0 o LaCie P3 HardDrive USB 200GB o Logitec LDR-H443U2 DVD-RAM/-R/+R/-RW/+RW drive o Logitec Mobile USB Memory LMC-256UD o Logitec USB1.1/2.0 HDD Unit SHD-E60U2 o Logitec USB Double-Speed Floppy Drive LFD-31U2 o Logitec USB/IEEE1394 DVD-RAM/R/RW Unit LDR-N21FU2 (CDROM only) o MELCO USB Flash Disk "ClipDrive", RUF-C32M, -C64M, -C128M, -C256M, -C512M o MELCO USB Flash Disk "PetitDrive", RUF-32M, -64M, -128M, -256Mm o MELCO USB2.0 Flash Disk "PetitDrive2", RUF-256M/U2, -512M/U2 o MELCO USB2.0 MO Drive MO-CH640U2 o Matshita CF-VFDU03 floppy drive o Merlin SM300 MP3/WMA Player (256Mb) o Microtech International, Inc. USB-SCSI-HD 50 USB to SCSI cable o Motorola E398 Mobile Phone (TransFlash memory card) o NOVAC USB2.0 2.5/3.5-inch HDD Case NV-HD351U o PNY Attache Flash Drive o Panasonic ("Matshita FDD CF-VFDU03") o Panasonic KXL-CB20AN Portable DVD-ROM/CD-R/RW o Panasonic KXL-CB35AN (DVD-ROM & CD-R/RW) o Panasonic USB2.0 Portable CD-RW Drive KXL-RW40AN (CDROM only) o Panasonic floppy drive o Qware BeatZkey! Pro o RATOC Systems USB2.0 Removable HDD Case U2-MDK1, U2-MDK1B o SanDisk SDDR-31 (Compact Flash) o SanDisk SDDR-75 (only Compact Flash port works) o Sitecom CN-300 MultiFlash (MMC/SD, SmartMedia, CF, MemoryStick) o Sony Portable CD-R/RW Drive CRX10U (CDROM only) o TEAC Portable USB CD-ROM Unit CD-110PU/210PU o Time DPA20B MP3 Player (1Gb) o Trek Thumbdrive 8MB o VAIO floppy drive (includes Y-E Data Flashbuster-U) o Y-E Data floppy drive (720/1.44/2.88Mb) Among the supported digital cameras are: o Asahi Optical (PENTAX) Optio 230 & 330 EXAMPLES
device umass device scbus device da device pass Add the umass driver to the kernel. camcontrol rescan 0 Rescan a Zip drive that was added after boot. The command above assumes that the Zip drive is on the first SCSI bus in the system. camcontrol rescan 0:0:0 camcontrol rescan 0:0:1 camcontrol rescan 0:0:2 camcontrol rescan 0:0:3 Rescan all slots on a multi-slot flash reader, where the slots map to separate LUNs on a single SCSI ID. Typically only the first slot will be enabled at boot time. Again, this assumes that the flash reader is the first SCSI bus in the system. bsdlabel -w da0 zip100 newfs da0c mount -t ufs /dev/da0c /mnt Write a disklabel to the Zip drive (see vpo(4) for the disktab(5) entry), creates the file system and mounts the new file system on /mnt. newfs_msdos /dev/da0 Create a new FAT type file system. Care should be taken not to run newfs(8) on devices that already contain data, as this will result in the information being lost. Many consumer devices such as digital cameras automatically create MS-DOS based file systems when storing information such as images and videos. These file systems can be accessed by specifying the file system type as msdos when using mount(8). SEE ALSO
ehci(4), ohci(4), uhci(4), usb(4), vpo(4), disktab(5), bsdlabel(8), camcontrol(8) AUTHORS
The umass driver was written by MAEKAWA Masahide <bishop@rr.iij4u.or.jp> and Nick Hibma <n_hibma@FreeBSD.org>. This manual page was written by Nick Hibma <n_hibma@FreeBSD.org>. BSD October 22, 2009 BSD
All times are GMT -4. The time now is 07:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy