Running a script when auto-mounter detects USB thumb-drive insertion...
Knowing linux, I know there has got to be a way to do this... however, not knowing linux well enough, I'm not sure how to go about it :scratch: Hopefully someone here can point me down the right path...
I have a script I run that sync's the contents of my USB thumb-drive to a directory on my harddrive and it works great... however, it's annoying to run... I'd like to find out what script the auto-mounter runs when I insert the USB stick so that I can see if I can just call my script from the end of the auto-mounter's script and thus sync my stuff automatically whenever I insert the stick... any ideas??? It may not matter, but for reference, I'm running openSUSE 10.2 ~Brandon |
Which desktop are you using. If it is KDE, a popup appears asking what you want to do. I think that could add an entry to the dialog and configure it to run your sync command.
There is a HAL helper script that I saw once, but I'm not certain under what circumstances it is called. Using "locate" might help pin it down. Also look at the process listing. I think there is a KDE daemon involved as well, which allows the user to graphically control the course of action to take. |
You can do this by useing udev rules:
Plug your thumbdrive in, and cat /proc/scsi/usb-storage/* You should find an entry for it similar to this: Host scsi7: usb-storage Vendor: Memorex Product: TRAVELDRIVE 005B Serial Number: 07751F9402C9 Protocol: Transparent SCSI Transport: Bulk Quirks: Now, with either the serial number or the vendor/model combo, you can write the rule. The rule creates a symlink for the device in the /dev tree, for example, /dev/TRAVELDRIVE create a text file in /etc/udev/rules.d called 95.usbbackup.rules. You can use a number other than 95, but keep in mind that udev processes rules in alphanumeric order, and it's better to have local rules processed last. If you have a serial number, type a rule like this (all on one line) into the file, and save it: BUS="usb", SYSFS{serial}="07751F9402C9", SYMLINK="TRAVELDRIVE", RUN+="/usr/local/bin/YOUR_SCRIPT.sh [Options if your script has them] " You can string as many SYSFS{} entries together as you need to identify the drive uniquely. BUS="scsi", SYSFS{vendor}==" Memorex", SYSFS{product}=="TRAVELDRIVE 005B ", SYMLINK="TRAVELDRIVE", RUN+="/usr/local/bin/backup-usbthumb.sh" Your rule now fires every time you plug in your thumbdrive. |
See the source of vsupdfstab-0.1-noarch-0.tgz:
/etc/vsupdfstab.udev Code:
#!/bin/bash /etc/udev/rules.d/usbflash.rules Code:
# /etc/udev/rules.d/usbflash.rules Quote:
|
Working code example of udev auto executing
Here a working code example of udev auto executing my usb thumb drive
file:///etc/udev/rules.d/10.usbtest.rules SUBSYSTEMS=="usb", ATTRS{serial}=="077B03B40D57", SYMLINK+="patriotUSB", RUN+="/usr/bin/beep" Code that will beep when any USB is plugged in SUBSYSTEMS=="usb", RUN+="/usr/bin/beep" NOTE: you probably might not have the action beep so just download it from your package manager :) I learned out do write this out correctly from this site reactivated.net/writing_udev_rules.html |
All times are GMT -5. The time now is 09:07 PM. |