Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 41

Thread: Running backup script with udev

  1. #31
    Join Date
    Mar 2008
    Beans
    4,715
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Running backup script with udev

    Hi Rackstar,
    Indeed, I had a dangling apostrophe in the script. I see you fixed it by adding single quotes around /etc/mtab. This is fine, though it is also fine to just remove the single quotes from both sides.

    I think the error on line 4 is caused by my forgetting to put $mount_point in quotes.
    When you forget the quotes, bash interprets space-separated words in the string as separate arguments. Hence, too many arguments to the [ (test) operator. When you put $mount_point in quotes, then the whole thing is regarded as one string.

    Also, one more improvement: Thanks to geirha (http://ubuntuforums.org/showthread.p...40#post6907640), we can reach our goal with one usb_backup.sh script instead of two scripts.

    Try placing this in /usr/local/bin/usb_backup.sh, and delete usb_backup_main.sh.

    Code:
    #!/bin/bash
    {
    mount_point=$(grep freecomHD /etc/mtab)
    attempts=1
    while [ -z "$mount_point" ] && [ "$attempts" -le 50 ]; do
        # $mount_point has not been found
        # quit if this fails more than 50 times. 
        # This should not be necessary, but it better to be safe
        # than have the script trapped in this loop forever for
        # some unforeseen reason.
        sleep 1
        mount_point=$(grep freecomHD /etc/mtab)
        attempts=$(($attempts+1))
    done
    
    if [ -n "$mount_point" ]; then
        su ruben alt-notify-send "Backup Message" "USB Backup device detected" 0
    
        # Insert rsync commands here
    
        su ruben alt-notify-send "Backup Message" "Your USB Backup has completed" 0
    fi
    } &
    Last edited by unutbu; March 17th, 2009 at 02:22 AM.

  2. #32
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Running backup script with udev

    Yep,

    You were right about the [test] commando, It came back to me, as soon as I started reading your post!

    This is it. A very clean solution! And really really fast if you tweak the rsync right. (Which was very easy actually, thumbs up!)

    I really think this will be usefull for many people.

    And three times hooray for Unutbu. Never knew that backupping could give me so much joy
    Last edited by Rackstar; March 25th, 2009 at 08:28 PM.

  3. #33
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Running backup script with udev


  4. #34
    Join Date
    Mar 2008
    Beans
    4,715
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Running backup script with udev

    Wow, very nice write up! Thank you for taking the time to do this. Contributions like this makes Linux better and better.

  5. #35
    Join Date
    Oct 2007
    Beans
    81

    Re: Running backup script with udev

    This type of command doesn't work for me:
    Code:
    su ruben alt-notify-send "Backup Message" "Your USB Backup has completed" 0
    Instead, I use
    Code:
    su -c 'alt-notify-send "Backup Message" "Your USB Backup has completed" 0' myusername
    This works well from the terminal but not from the script. Any ideas why?

  6. #36
    Join Date
    Mar 2008
    Beans
    4,715
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Running backup script with udev

    Is your setup exactly like the one described in http://ninetynine.be/blog/2009/03/ub...ive-on-mount/?

    If not, how does yours differ?

  7. #37
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Running backup script with udev

    Mihaicj, has your problem been solved about the script 'firing 14 times', that you posted on my blog?

    We can offer you some help if you want to.

  8. #38
    Join Date
    Feb 2006
    Location
    The Netherlands
    Beans
    209
    Distro
    Xubuntu 8.10 Intrepid Ibex

    Re: Running backup script with udev

    Quote Originally Posted by Rackstar View Post
    Mihaicj, has your problem been solved about the script 'firing 14 times', that you posted on my blog?

    We can offer you some help if you want to.
    Hmm I just started a thread explaining the same problem.

    My udev rule works fine, my script gets executed perfectly, albeit 14 times or so. I am not sure how this is happening, but I really don't want my USB stick to get backed up 14 times

    Any ideas?
    The mumak butts! The grid bug bites! You get zapped! -- More --
    The leocrotta kicks! You die... -- More --
    Do you want your possessions identified? (y/n)

  9. #39
    Join Date
    Nov 2007
    Location
    North by Northwest
    Beans
    194
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Running backup script with udev

    Sorry to bring this thread back from the grave but I was going to post a question with the exact same topic.


    I am also wanting to run a backup script that runs every time a USB drive is connected but it appears that my udev rules just aren't working and I can't for the life of me figure out how.

    I've tried a large number of rules but none seem to work. Here's my current trial:
    Code:
    SUBSYSTEMS=="usb", ATTRS="02AD00000003Ad", RUN+="/usr/lib/myscript.sh"
    I know my script works as I can run it from the command line and it works just fine and I've fiddled with permissions so that doesn't seem to be an issue either.

    So can anyone help me with the udev rules?

    EDIT: Here's my output from "udevadm info -a -p $(udevadm info -q path -n /dev/sdb)"
    Code:
    udevadm info -a -p $(udevadm info -q path -n /dev/sdb)
    
    Udevadm info starts with the device specified by the devpath and then
    walks up the chain of parent devices. It prints for every device
    found, all possible attributes in the udev rules key format.
    A rule to match, can be composed by the attributes of the device
    and the attributes from one single parent device.
    
      looking at device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host6/target6:0:0/6:0:0:0/block/sdb':
        KERNEL=="sdb"
        SUBSYSTEM=="block"
        DRIVER==""
        ATTR{range}=="16"
        ATTR{ext_range}=="256"
        ATTR{removable}=="1"
        ATTR{ro}=="0"
        ATTR{size}=="0"
        ATTR{alignment_offset}=="0"
        ATTR{capability}=="53"
        ATTR{stat}=="     106      276      781      224        2        0        2        0        0      212      224"
        ATTR{inflight}=="       0        0"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host6/target6:0:0/6:0:0:0':
        KERNELS=="6:0:0:0"
        SUBSYSTEMS=="scsi"
        DRIVERS=="sd"
        ATTRS{device_blocked}=="0"
        ATTRS{type}=="0"
        ATTRS{scsi_level}=="3"
        ATTRS{vendor}=="Pretec  "
        ATTRS{model}=="256MB Tiny      "
        ATTRS{rev}=="1.20"
        ATTRS{state}=="running"
        ATTRS{timeout}=="30"
        ATTRS{iocounterbits}=="32"
        ATTRS{iorequest_cnt}=="0x1bc"
        ATTRS{iodone_cnt}=="0x1bc"
        ATTRS{ioerr_cnt}=="0x123"
        ATTRS{modalias}=="scsi:t-0x00"
        ATTRS{evt_media_change}=="0"
        ATTRS{dh_state}=="detached"
        ATTRS{queue_depth}=="1"
        ATTRS{queue_type}=="none"
        ATTRS{max_sectors}=="240"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host6/target6:0:0':
        KERNELS=="target6:0:0"
        SUBSYSTEMS=="scsi"
        DRIVERS==""
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host6':
        KERNELS=="host6"
        SUBSYSTEMS=="scsi"
        DRIVERS==""
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0':
        KERNELS=="1-1:1.0"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb-storage"
        ATTRS{bInterfaceNumber}=="00"
        ATTRS{bAlternateSetting}==" 0"
        ATTRS{bNumEndpoints}=="03"
        ATTRS{bInterfaceClass}=="08"
        ATTRS{bInterfaceSubClass}=="06"
        ATTRS{bInterfaceProtocol}=="50"
        ATTRS{modalias}=="usb:v4146pBA01d0100dc00dsc00dp00ic08isc06ip50"
        ATTRS{supports_autosuspend}=="0"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1':
        KERNELS=="1-1"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb"
        ATTRS{configuration}==""
        ATTRS{bNumInterfaces}==" 1"
        ATTRS{bConfigurationValue}=="1"
        ATTRS{bmAttributes}=="80"
        ATTRS{bMaxPower}==" 98mA"
        ATTRS{urbnum}=="1926"
        ATTRS{idVendor}=="4146"
        ATTRS{idProduct}=="ba01"
        ATTRS{bcdDevice}=="0100"
        ATTRS{bDeviceClass}=="00"
        ATTRS{bDeviceSubClass}=="00"
        ATTRS{bDeviceProtocol}=="00"
        ATTRS{bNumConfigurations}=="1"
        ATTRS{bMaxPacketSize0}=="64"
        ATTRS{speed}=="480"
        ATTRS{busnum}=="1"
        ATTRS{devnum}=="3"
        ATTRS{version}==" 2.00"
        ATTRS{maxchild}=="0"
        ATTRS{quirks}=="0x0"
        ATTRS{authorized}=="1"
        ATTRS{product}=="USB Mass Storage Device"
        ATTRS{serial}=="02AD00000003AD"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1':
        KERNELS=="usb1"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb"
        ATTRS{configuration}==""
        ATTRS{bNumInterfaces}==" 1"
        ATTRS{bConfigurationValue}=="1"
        ATTRS{bmAttributes}=="e0"
        ATTRS{bMaxPower}=="  0mA"
        ATTRS{urbnum}=="50"
        ATTRS{idVendor}=="1d6b"
        ATTRS{idProduct}=="0002"
        ATTRS{bcdDevice}=="0206"
        ATTRS{bDeviceClass}=="09"
        ATTRS{bDeviceSubClass}=="00"
        ATTRS{bDeviceProtocol}=="00"
        ATTRS{bNumConfigurations}=="1"
        ATTRS{bMaxPacketSize0}=="64"
        ATTRS{speed}=="480"
        ATTRS{busnum}=="1"
        ATTRS{devnum}=="1"
        ATTRS{version}==" 2.00"
        ATTRS{maxchild}=="8"
        ATTRS{quirks}=="0x0"
        ATTRS{authorized}=="1"
        ATTRS{manufacturer}=="Linux 2.6.32-24-generic ehci_hcd"
        ATTRS{product}=="EHCI Host Controller"
        ATTRS{serial}=="0000:00:1d.7"
        ATTRS{authorized_default}=="1"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7':
        KERNELS=="0000:00:1d.7"
        SUBSYSTEMS=="pci"
        DRIVERS=="ehci_hcd"
        ATTRS{vendor}=="0x8086"
        ATTRS{device}=="0x27cc"
        ATTRS{subsystem_vendor}=="0x17aa"
        ATTRS{subsystem_device}=="0x380b"
        ATTRS{class}=="0x0c0320"
        ATTRS{irq}=="16"
        ATTRS{local_cpus}=="ff"
        ATTRS{local_cpulist}=="0-7"
        ATTRS{modalias}=="pci:v00008086d000027CCsv000017AAsd0000380Bbc0Csc03i20"
        ATTRS{broken_parity_status}=="0"
        ATTRS{msi_bus}==""
        ATTRS{companion}==""
    
      looking at parent device '/devices/pci0000:00':
        KERNELS=="pci0000:00"
        SUBSYSTEMS==""
        DRIVERS==""
    Last edited by OlyPerson; July 30th, 2010 at 09:01 PM.

  10. #40
    Join Date
    Aug 2010
    Location
    Ufa, Russian Federation
    Beans
    3
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Running backup script with udev

    I've tried a large number of rules but none seem to work. Here's my current trial:
    Code:
    SUBSYSTEMS=="usb", ATTRS="02AD00000003Ad", RUN+="/usr/lib/myscript.sh"
    Why don't you use ATTRS{serial} instead of ATTRS?
    If it will not help, try to delete ATTRS attribute. AFAIK this rule will trigger every usb device.

Page 4 of 5 FirstFirst ... 2345 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •