Results 1 to 10 of 41

Thread: Running backup script with udev

Hybrid View

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

    [SOLVED] Running backup script with udev

    Hello,

    I have been trying to get my backup script running when I plug my USB dive in.

    But it still seems that it refuses to work...

    These are my rules: (in /etc/udev/rules.d/10-local.rules)
    Code:
    SUBSYSTEM=="block", ATTRS{product}=="Freecom Network Drive", SUBSYSTEMS=="usb", KERNEL=="sd?1", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"
    with /usr/bin/usb_backup.sh
    Code:
    #!/bin/bash
    /usr/bin/notify-send -t 0 "Backup Message" "Backup device detected, starting backup."
    sleep 5
    sbackupd
    /usr/bin/notify-send -t 0 "Backup Message" "Your USB Backup has completed."
    The script runs as it should when I manually run it as root.


    This is what I get when I do "udevinfo -a -p $(udevinfo -q path -n /dev/sdb)".

    Code:
    looking at device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5/target5:0:0/5:0:0:0/block/sdb':
        KERNEL=="sdb"
        SUBSYSTEM=="block"
        DRIVER==""
        ATTR{range}=="16"
        ATTR{removable}=="0"
        ATTR{ro}=="0"
        ATTR{size}=="976773168"
        ATTR{capability}=="12"
        ATTR{stat}=="     439    30507    32116     2328        0        0        0        0        0     1604     2328"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5/target5:0:0/5:0:0:0/block':
        KERNELS=="block"
        SUBSYSTEMS==""
        DRIVERS==""
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5/target5:0:0/5:0:0:0':
        KERNELS=="5:0:0:0"
        SUBSYSTEMS=="scsi"
        DRIVERS=="sd"
        ATTRS{device_blocked}=="0"
        ATTRS{type}=="0"
        ATTRS{scsi_level}=="3"
        ATTRS{vendor}=="WDC WD50"
        ATTRS{model}=="00AAVS-00G9B0   "
        ATTRS{rev}=="    "
        ATTRS{state}=="running"
        ATTRS{timeout}=="30"
        ATTRS{iocounterbits}=="32"
        ATTRS{iorequest_cnt}=="0x1c5"
        ATTRS{iodone_cnt}=="0x1c5"
        ATTRS{ioerr_cnt}=="0x0"
        ATTRS{modalias}=="scsi:t-0x00"
        ATTRS{evt_media_change}=="0"
        ATTRS{queue_depth}=="1"
        ATTRS{queue_type}=="none"
        ATTRS{max_sectors}=="240"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5/target5:0:0':
        KERNELS=="target5:0:0"
        SUBSYSTEMS=="scsi"
        DRIVERS==""
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5':
        KERNELS=="host5"
        SUBSYSTEMS=="scsi"
        DRIVERS==""
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0':
        KERNELS=="5-6:1.0"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb-storage"
        ATTRS{bInterfaceNumber}=="00"
        ATTRS{bAlternateSetting}==" 0"
        ATTRS{bNumEndpoints}=="02"
        ATTRS{bInterfaceClass}=="08"
        ATTRS{bInterfaceSubClass}=="06"
        ATTRS{bInterfaceProtocol}=="50"
        ATTRS{modalias}=="usb:v07ABpFCBFd0000dc00dsc00dp00ic08isc06ip50"
        ATTRS{interface}=="MSC Bulk-Only Transfer"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6':
        KERNELS=="5-6"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb"
        ATTRS{configuration}=="USB Mass Storage"
        ATTRS{bNumInterfaces}==" 1"
        ATTRS{bConfigurationValue}=="1"
        ATTRS{bmAttributes}=="c0"
        ATTRS{bMaxPower}=="  2mA"
        ATTRS{urbnum}=="5170"
        ATTRS{idVendor}=="07ab"
        ATTRS{idProduct}=="fcbf"
        ATTRS{bcdDevice}=="0000"
        ATTRS{bDeviceClass}=="00"
        ATTRS{bDeviceSubClass}=="00"
        ATTRS{bDeviceProtocol}=="00"
        ATTRS{bNumConfigurations}=="1"
        ATTRS{bMaxPacketSize0}=="64"
        ATTRS{speed}=="480"
        ATTRS{busnum}=="5"
        ATTRS{devnum}=="8"
        ATTRS{version}==" 2.00"
        ATTRS{maxchild}=="0"
        ATTRS{quirks}=="0x0"
        ATTRS{authorized}=="1"
        ATTRS{manufacturer}=="0"
        ATTRS{product}=="Freecom Network Drive"
        ATTRS{serial}=="7D5000AA6350"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5':
        KERNELS=="usb5"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb"
        ATTRS{authorized_default}=="1"
        ATTRS{configuration}==""
        ATTRS{bNumInterfaces}==" 1"
        ATTRS{bConfigurationValue}=="1"
        ATTRS{bmAttributes}=="e0"
        ATTRS{bMaxPower}=="  0mA"
        ATTRS{urbnum}=="147"
        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}=="5"
        ATTRS{devnum}=="1"
        ATTRS{version}==" 2.00"
        ATTRS{maxchild}=="8"
        ATTRS{quirks}=="0x0"
        ATTRS{authorized}=="1"
        ATTRS{manufacturer}=="Linux 2.6.27-11-generic ehci_hcd"
        ATTRS{product}=="EHCI Host Controller"
        ATTRS{serial}=="0000:00:1d.7"
    
      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}=="0x1025"
        ATTRS{subsystem_device}=="0x0107"
        ATTRS{class}=="0x0c0320"
        ATTRS{irq}=="23"
        ATTRS{local_cpus}=="ffffffff,ffffffff"
        ATTRS{local_cpulist}=="0-63"
        ATTRS{modalias}=="pci:v00008086d000027CCsv00001025sd00000107bc0Csc03i20"
        ATTRS{broken_parity_status}=="0"
        ATTRS{msi_bus}==""
    
      looking at parent device '/devices/pci0000:00':
        KERNELS=="pci0000:00"
        SUBSYSTEMS==""
        DRIVERS==""
    Can anybody see the problem?
    Last edited by Rackstar; March 13th, 2009 at 07:53 PM.

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

    Re: Running backup script with udev

    I think the udev rule should specify SUBSYSTEMS only once. So perhaps try changing

    Code:
    SUBSYSTEM=="block", ATTRS{product}=="Freecom Network Drive", SUBSYSTEMS=="usb", KERNEL=="sd?1", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"
    to
    Code:
    ATTRS{product}=="Freecom Network Drive", SUBSYSTEMS=="usb", KERNEL=="sd?1", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"

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

    Re: Running backup script with udev

    Hey,

    Thanks for the fast reply!

    But still nothing happens. (Also one was SUBSYSTEM, other was SUBSYSTEMS)

    EDIT: the rules this time
    Code:
    SUBSYSTEMS=="usb", KERNEL=="sd?1", ATTRS{product}=="Freecom Network Drive", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"
    Thanks. Any other idea?

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

    Re: Running backup script with udev

    Oops, indeed you are right -- SUBSYSTEM and SUBSYSTEMS are different.
    • Did you run
      Code:
      sudo udevadm control --reload-rules
      after changing the udev rule?
    • It would be nice to know if (A) the script is being run, but quitting early, or (B) the script in never getting run at all.

      If we are in case (A), then we can stop fiddling with the udev rule and concentrate on the script.

      If (B), then we need to work on the udev rule.

      To find out if we are in case (A) or (B), perhaps try this: Edit your script by adding these two lines:
      Code:
      #!/bin/bash
      env > /tmp/env.out
      DISPLAY=:0.0
      /usr/bin/notify-send -t 0 "Backup Message" "Backup device detected, starting backup."
      sleep 5
      sbackupd
      /usr/bin/notify-send -t 0 "Backup Message" "Your USB Backup has completed."
      Run
      Code:
      sudo udevadm control --reload-rules
      Unplug and then plug in the drive. See if you get a file called /tmp/env.out.

      If you see /tmp/env.out, then we are in case (A).

      If you do not see /tmp/env.out, then we are in case (B).

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

    Re: Running backup script with udev

    Thank you very much for helping me out with this one!

    I used
    Code:
    sudo /etc/init.d/udev restart
    to restart it.

    I tried yours but It said:
    Code:
    ruben@ruben-laptop:~$ sudo udevadm control --reload-rules
    unrecognized command 'reload-rules'
    Some package missing?

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

    Re: Running backup script with udev

    For some reason, he does not want to mount the drive anymore? (Gives error dialog box)

    The env.out file is there! But no backup

    Thanks!

    See files:
    http://www.ninetynine.be/screens/76c...f8026bd192.png
    http://www.ninetynine.be/screens/c81...1a48d770ec.png

    Extra details:
    http://www.ninetynine.be/screens/7f9...92a7372bbe.png

    (please note that I was able to normally use the HDD in the past. The HDD is formatted into NTFS)
    Last edited by Rackstar; March 12th, 2009 at 08:37 PM. Reason: New files

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
  •