Score:1

Detach process from execution thread

cn flag

I am launching a script with a udev rules on every usb device connection. The issue is than i need than this script to launch another one after 20 seconds.

This is the code.

#!/bin/bash
#
sleep 20
/'Another Script'

The problem is than doing like this with delay the udev mount operation, what i do not want to happen.

Have tried this:

#!/bin/bash
#
nohup bash /'Other Script' & 
fg

Putting the waiting inside the 'Other Script'.

SOLVED

The udev rule was launched with RUN{type}, that was the problem, it cannot handle long process, i just create a systemd service and lauch it using ENV{SYSTEMD_WANTS} on the udev rules and like silk.

Do this:

/etc/udev/rules.d/99-usb.rules

    ACTION=="add", ENV{SYSTEMD_WANTS}="usb.service"

/etc/systemd/system/usb.service

    [Unit]
    Description=USB Autorun.
    
    [Service]
    Type=oneshot
    ExecStart=/Script.sh

/Script.sh

    #!/bin/bash
    #
    sleep 20
    /'Another Script'
in flag
One option may be `bash other.sh & disown`
Jobesmor avatar
cn flag
i try but was getting a weird behavior, i read a little turns out than if the one terminal process who 'launch' end before the 'launched' then the last one is also closed, fun fact on 18.04 late, works like silk, but need it to work on 16.04 at least
bac0n avatar
cn flag
consult the `udev` manual `RUN{type}`
bac0n avatar
cn flag
Related: [Why is my udev rule not working?](https://askubuntu.com/a/1222166/986805)
Zanna avatar
kr flag
Does the linked post solve your problem?
muru avatar
us flag
Starting a systemd unit shouldn't block udev, so that's how you should do it instead of messing around with sleep and nohup.
fuzzy drawings avatar
tj flag
He could use `at now -f scrip2.sh` to launch the other script. That won't block `udev` either. OP says he needs the 20 second delay for whatever reason, so having `scrip2.sh` start with `sleep 20` would work without requiring a systemd `.service` entry.
Jobesmor avatar
cn flag
I also try it with "at now -f" and use "sleep" at start of the script, do not work for me, again not realy sure witch cause on 18+ works fine.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.