Re: script on unmount
Jackson Cooper wrote: True.. So then perhaps you could do something if umount's exit status isn't 0... It'll still fail when the device is busy, but won't be stuck in an infinite loop. eg. CODE while true; do if [[ -d /media/nameofdongle ]]; then rsync -switches /media/nameofdongle /some/other/path error=$(umount -switches /media/nameofdongle 21) if [ $? != 0 ]; then echo $(date): Error when un-mounting: $error /var/log/usb_rsync_errors.log exit 1 fi else sleep 1 fi done /CODE Also, you could use dbus-send to unmount it, it *may* be a bit cleaner. The command's in the format of dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/volume_uuid_UUIDGOESHERE org.freedesktop.Hal.Device.Volume.UnMount - Jackson On Sat, Apr 12, 2008 at 3:33 PM, Frode Egeland [EMAIL PROTECTED] wrote: Oops, I didn't spot the umount until after I hit send.. apologies. :) The umount would do the trick, assuming nothing else makes the device busy, THEN you'd get the infinite loop I was worried about. ;) Hi Jackson, Hi Frode, as I am not really familiar with this I wanted to try something I already figured out (with lots of forum reading :-) ) so I created a udev rule: sudo gedit /etc/udev/rules.d/85-usb_legend.rules it reads SUBSYSTEMS==“scsi”,DRIVERS==“sd”,KERNEL==”[0-9]*”,ATTRS{model}==“USB Flash Disk ”,ATTRS{vendor}==“General ”,RUN+=”/home/seb/bin/legend_sync_mount.sh %k” in the shell script I then call rsync #!/bin/sh rsync -avS -P /media/LEGEND/Documents/sync/TaskCoach/* /home/seb/sync/TaskCoach somehow this is 99% similar to another script I set up to fix my external hdd the only difference is the command called by the script, the scripts location (not in my home) and the ATTRS attributes I am puzzled... why it is not working? As for your solution it seemed to me that it fits not my usage scenario: - home after work - plug in and synch - do something with the files on local hdd - before unmount sync new/changed filed back to USB When I get your idea right it will unmount right away!? Still I would like to test you idea but I am not sure where to place your code. in a shell script I assume. I have no idea about the daemon though. RE umount of busy drive I could use the lazy option. Cheers, Sebastian -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au
Re: script on unmount
Jackson Cooper wrote: Sebastian, The way I'd do it is create a daemon with an infinite loop (I don't know much about udev though) that looks for the folder /media/nameofusbdongle, and if it exists execute the rsync line, then an umount line. Something like... CODE while true; do if [[ -d /media/nameofdongle ]]; then rsync -switches /media/nameofdongle /some/other/path umount -switches /media/nameofdongle else sleep 1 fi done /CODE Then to make it a daemon, you could use the start-stop-daemon program. Type man start-stop-daemon in the terminal to find out more. - Jackson On Fri, Apr 11, 2008 at 7:55 PM, Sebastian Spiess [EMAIL PROTECTED] wrote: hi all, I want to sync some of my USB dongle folders when I plug it in. I think I worked that out: create a rule /etc/udev/rules.d/85-usbstick.rules and call the script to sync. But how about when I want to unplug the thing? Then there is no usb/hotplug event. Would the simplest thing be a script with unmount/eject at the end? How could I call this script through the icon (unmount menu) on the desktop? How to make the eject/unmount wait until rsync is done? by the way what's the difference between unmount and eject? thanks Sebastian -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au bugger, I missed you mentioning man start-stop-daemon -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au
Re: script on unmount
Sebastian Spiess wrote: ... As for your solution it seemed to me that it fits not my usage scenario: - home after work - plug in and synch - do something with the files on local hdd - before unmount sync new/changed filed back to USB When I get your idea right it will unmount right away!? Still I would like to test you idea but I am not sure where to place your code. in a shell script I assume. I have no idea about the daemon though. RE umount of busy drive I could use the lazy option. A couple of things to consider here (if i'm understanding your goals correctly): - Unison is a utility that uses the rsync algorithm to do bi-directional sync. This means that you don't have to manage the bidirectional rsync options yourself, but just run Unison every time either side changes. - You can get GNOME to run a custom command on insertion of different media types using System-Preferences-Removable Drives and Media. I use this to sync my digital camera cards by getting it to run a script which syncs the files (unidirectionally, in this case), then umount the SD card. Then there's no need to run a daemon or poll a driver. A possible down side to this is that you need to be logged in. Paul smime.p7s Description: S/MIME Cryptographic Signature -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au
Re: script on unmount
True.. So then perhaps you could do something if umount's exit status isn't 0... It'll still fail when the device is busy, but won't be stuck in an infinite loop. eg. CODE while true; do if [[ -d /media/nameofdongle ]]; then rsync -switches /media/nameofdongle /some/other/path error=$(umount -switches /media/nameofdongle 21) if [ $? != 0 ]; then echo $(date): Error when un-mounting: $error /var/log/usb_rsync_errors.log exit 1 fi else sleep 1 fi done /CODE Also, you could use dbus-send to unmount it, it *may* be a bit cleaner. The command's in the format of dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/volume_uuid_UUIDGOESHERE org.freedesktop.Hal.Device.Volume.UnMount - Jackson On Sat, Apr 12, 2008 at 3:33 PM, Frode Egeland [EMAIL PROTECTED] wrote: Oops, I didn't spot the umount until after I hit send.. apologies. :) The umount would do the trick, assuming nothing else makes the device busy, THEN you'd get the infinite loop I was worried about. ;) -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au
Re: script on unmount
Sebastian, The way I'd do it is create a daemon with an infinite loop (I don't know much about udev though) that looks for the folder /media/nameofusbdongle, and if it exists execute the rsync line, then an umount line. Something like... CODE while true; do if [[ -d /media/nameofdongle ]]; then rsync -switches /media/nameofdongle /some/other/path umount -switches /media/nameofdongle else sleep 1 fi done /CODE Then to make it a daemon, you could use the start-stop-daemon program. Type man start-stop-daemon in the terminal to find out more. - Jackson On Fri, Apr 11, 2008 at 7:55 PM, Sebastian Spiess [EMAIL PROTECTED] wrote: hi all, I want to sync some of my USB dongle folders when I plug it in. I think I worked that out: create a rule /etc/udev/rules.d/85-usbstick.rules and call the script to sync. But how about when I want to unplug the thing? Then there is no usb/hotplug event. Would the simplest thing be a script with unmount/eject at the end? How could I call this script through the icon (unmount menu) on the desktop? How to make the eject/unmount wait until rsync is done? by the way what's the difference between unmount and eject? thanks Sebastian -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au
Re: script on unmount
That would seem to repeatedly call rsync as long as the folder is there. Probably not what you wanted. Anyone have a better way? :) On Sat, Apr 12, 2008 at 10:57 AM, Jackson Cooper [EMAIL PROTECTED] wrote: Sebastian, The way I'd do it is create a daemon with an infinite loop (I don't know much about udev though) that looks for the folder /media/nameofusbdongle, and if it exists execute the rsync line, then an umount line. Something like... CODE while true; do if [[ -d /media/nameofdongle ]]; then rsync -switches /media/nameofdongle /some/other/path umount -switches /media/nameofdongle else sleep 1 fi done /CODE Then to make it a daemon, you could use the start-stop-daemon program. Type man start-stop-daemon in the terminal to find out more. - Jackson On Fri, Apr 11, 2008 at 7:55 PM, Sebastian Spiess [EMAIL PROTECTED] wrote: hi all, I want to sync some of my USB dongle folders when I plug it in. I think I worked that out: create a rule /etc/udev/rules.d/85-usbstick.rules and call the script to sync. But how about when I want to unplug the thing? Then there is no usb/hotplug event. Would the simplest thing be a script with unmount/eject at the end? How could I call this script through the icon (unmount menu) on the desktop? How to make the eject/unmount wait until rsync is done? by the way what's the difference between unmount and eject? thanks Sebastian -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au -- http://www.kiva.org/lender/frode -- ubuntu-au mailing list ubuntu-au@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-au