Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 43

Thread: howto run a script when a USB device is pluged in

  1. #21
    Join Date
    Nov 2005
    Location
    Santiago, Chile
    Beans
    47
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: howto run a script when a USB device is pluged in

    Green_Star

    I know it's an old post, but, were you able to solve this problem?

    If not, I'm thinking you cannot run your script since it's not run inside the window manager. I'm guessing there's a way to run it so it's executed in gnome (if that's what your running).

    Cheers

  2. #22
    Join Date
    Jan 2007
    Location
    Belo Horizonte, Brazil
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: howto run a script when a USB device is pluged in

    Quote Originally Posted by techflat View Post
    Green_Star

    I know it's an old post, but, were you able to solve this problem?

    If not, I'm thinking you cannot run your script since it's not run inside the window manager. I'm guessing there's a way to run it so it's executed in gnome (if that's what your running).

    Cheers
    I found the answer by adapting the script from this thread, ending with something like this:

    Code:
    #!/bin/bash
    set -x 
    xhost local:MYUSERNAME
    export DISPLAY=:0.0
    
    su MYUSERNAME -c '/usr/local/bin/my_script args1 arg2 etc'
    
    ## (Optional) Put a notification-icon into the system tray
    #/usr/bin/zenity --notification --window-icon=/usr/share/pixmaps/gnome-irc.png --text="the USB stuff was connected!"
    It succesfully run some GUI app!
    Last edited by everthonvaladao; March 19th, 2009 at 08:45 PM.

  3. #23
    Join Date
    Jan 2008
    Beans
    250
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: howto run a script when a USB device is pluged in

    This doesn't work at all for me.
    Code:
    ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="040d", SYSFS{idProduct}=="6204", RUN+="/usr/share/scripts/backup.sh"
    Quad core AMD Phenom - 4 GB RAM - 2 1TB hard drives

  4. #24
    Join Date
    Mar 2007
    Location
    Denver, CO
    Beans
    7,721
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: howto run a script when a USB device is pluged in

    roanake, please review the name conventions requred for your script.

  5. #25
    Join Date
    Jan 2008
    Beans
    250
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: howto run a script when a USB device is pluged in

    The numbers and the dash are only required for the rules file. This line is inside the rules file, which is named 85-myrule.rules.
    Quad core AMD Phenom - 4 GB RAM - 2 1TB hard drives

  6. #26
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: howto run a script when a USB device is pluged in

    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 this line:
    Code:
    env > /tmp/env.out
    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). In this case, please post your script.

    If you do not see /tmp/env.out, then we are in case (B). In this case, please post the output of lsusb.

  7. #27
    Join Date
    Jan 2008
    Beans
    250
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: howto run a script when a USB device is pluged in

    The file didn't appear in /tmp, so here's lsusb's output.
    Code:
    Bus 005 Device 016: ID 040d:6204 VIA Technologies, Inc. 
    Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Quad core AMD Phenom - 4 GB RAM - 2 1TB hard drives

  8. #28
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: howto run a script when a USB device is pluged in

    Try removing SUBSYSTEM=="usb_device":
    Code:
    ACTION=="add", SYSFS{idVendor}=="040d", SYSFS{idProduct}=="6204", RUN+="/usr/share/scripts/backup.sh"
    Also make sure that /usr/share/scripts/backup.sh is executable:
    Code:
    sudo chmod 755 /usr/share/scripts/backup.sh
    Unplug and plug in the device once more. Check for /tmp/env.out.
    If you don't see /tmp/env.out, run
    Code:
    for dev in $(ls /sys/bus/usb/devices); do udevinfo -ap /sys/bus/usb/devices/$dev; done > udevinfo.txt
    
    awk 'BEGIN { RS=""; FS="n"; PATTERN="040d" } { if ( $0 ~ PATTERN ) print $0; }' udevinfo.txt > 040d.txt
    Then post 040d.txt.

  9. #29
    Join Date
    Jan 2008
    Beans
    250
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: howto run a script when a USB device is pluged in

    Thank you, that worked
    Quad core AMD Phenom - 4 GB RAM - 2 1TB hard drives

  10. #30
    Join Date
    Nov 2005
    Location
    Santiago, Chile
    Beans
    47
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: howto run a script when a USB device is pluged in

    Quote Originally Posted by everthonvaladao View Post
    I found the answer by adapting the script from this thread, ending with something like this:

    Code:
    #!/bin/bash
    set -x 
    xhost local:MYUSERNAME
    export DISPLAY=:0.0
    
    su MYUSERNAME -c '/usr/local/bin/my_script args1 arg2 etc'
    
    ## (Optional) Put a notification-icon into the system tray
    #/usr/bin/zenity --notification --window-icon=/usr/share/pixmaps/gnome-irc.png --text="the USB stuff was connected!"
    It succesfully run some GUI app!
    Nice. Just a question, what does the xhost local:MYUSERNAME do?

Page 3 of 5 FirstFirst 12345 LastLast

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
  •