Results 1 to 6 of 6

Thread: [bash, udev]: How do you detach a script?

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

    [SOLVED] [bash, udev]: How do you detach a script?

    I would like to launch a script via a udev rule:

    Code:
    cat /etc/udev/rules.d/81-local.rules
    SUBSYSTEM=="block", SUBSYSTEMS=="usb", KERNEL=="sd?1", RUN+="/home/user/bin/test.sh"
    The problem is test.sh takes a long time to run (it is a backup script), and HAL does not mount the partitions correctly if test.sh takes too much time.

    This problem is discussed here: /usr/share/doc/udev/writing_udev_rules/index.html
    [the script] must not run for any extended period of time, because udev is effectively paused while these programs are running. One workaround for this limitation is to make sure your program immediately detaches itself.
    How do you write a script that detaches itself?

    I've tried modifying the udev rule by putting an ampersand at the end of the command
    Code:
    SUBSYSTEM=="block", SUBSYSTEMS=="usb", KERNEL=="sd?1", RUN+="/home/user/bin/test.sh &"
    This does not work.

    So here is my crude workaround:
    Code:
    cat test.sh
    #!/bin/sh
    test2.sh &
    
    cat test2.sh
    #!/bin/sh
    <...insert backup commands here...>
    This works, but it feels wrong. Is there a more elegant way to do this?
    Last edited by unutbu; April 15th, 2009 at 09:33 PM.

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: [bash, udev]: How do you detach a script?

    Try grouping the commands in the script, and send the group to the background.
    Code:
    #!/bin/sh
    {
    <...insert backup commands here...>
    } &

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

    Re: [bash, udev]: How do you detach a script?

    Thank you geirha, this works great!

  4. #4
    Join Date
    Apr 2005
    Beans
    849

    Re: [bash, udev]: How do you detach a script?

    Quote Originally Posted by geirha View Post
    Try grouping the commands in the script, and send the group to the background.
    Code:
    #!/bin/sh
    {
    <...insert backup commands here...>
    } &
    Thats a new one,
    I guess this is worth remembering.
    Running 8.10 on a lenovo 3000 n200!
    Fingerprint reader doesn't work.

  5. #5
    Join Date
    Sep 2006
    Beans
    2,914

    Re: [bash, udev]: How do you detach a script?

    Quote Originally Posted by monkeyking View Post
    Thats a new one,
    I guess this is worth remembering.
    That's not new at all. All documented. See here example 3-1

  6. #6
    Join Date
    Mar 2012
    Beans
    1

    Re: [bash, udev]: How do you detach a script?

    This is indeed worth remembering... I've been searching quite a long time for a solution to this udev run script detach problem. Never imagined the solution to be so easy to solve

    Very elegant=D>

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
  •