Results 1 to 5 of 5
I'm currently working on a script which would check if a cdrom/pendrive is inserted (and not yet mounted) and mount it to some directory (name determined by for example device ...
- 12-10-2009 #1Just Joined!
- Join Date
- Dec 2009
- Posts
- 1
BASH scripting - detect if cdrom/pendrive inserted
I'm currently working on a script which would check if a cdrom/pendrive is inserted (and not yet mounted) and mount it to some directory (name determined by for example device name).
However I'm stuck at the very beginning - how to check if cdrom/pendrive is inserted?
What I'm aiming for is to get its /dev/ location.
Yea I know that it's already implemented in 90% of distros, the script is for educational purposes;P
- 01-24-2010 #2Just Joined!
- Join Date
- Sep 2006
- Posts
- 5
From what little I know ....
Whenever you insert a pendrive, a log records the action.
run "dmesg" (as root) after inserting the pendrive and you should see some entries (toward the end of the log) about "Sandisk Pro Disk ...." or whatever your pendrive manufacturer is.
then some lines with .../dev/sdb (or sdc, sdd, sde) depending on the amount of drives that you have on this computer.
ect .....
I beleive that you can use this output as your jump point for your script .....
- 01-24-2010 #3Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
You could use HAL tools also :
Code:#Get the HAL UDI(Unique Device Identifier) for the DVD drive, from he output list of : hal-find-by-capability --capability storage #Ask HAL if a media is in the drive hal-get-property --udi <your_dvd_udi> --key storage.removable.media_available
- 01-26-2010 #4
When I plug in a USB thumb drive, an entry is added to /proc/bus/usb/devices which has some interesting information.
I wonder if it's possible to map the information (e.g. "Bus=02 Lev=01 Prnt=01 Port=00...) to a device in /dev.
- 01-26-2010 #5Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
I don't know how to map the info in /proc.../devices to a /dev/???
You can get this /dev/??? through HAL tools.
Code:#get the HAL UDI for the storage (HAL language) hal-find-by-capability --capability storage #get the UDI of a volume (HAL language) in the storage hal-find-by-property --key block.storage_device --string /org/freedesktop/Hal/devices/storage_serial_SOME_LABEL #get the property you are looking for hal-get-property --udi /org/freedesktop/Hal/devices/volume_uuid_XXXX_YYYY --key block.device #sidenote #hal-device > /tmp/devices.txt will list all your devices managed by HAL.


Reply With Quote
