0

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'
  • 3
    One option may be bash other.sh & disown – matigo Jan 27 '22 at 15:16
  • 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 – Jobesmor Jan 27 '22 at 17:03
  • 1
    consult the udev manual RUN{type} –  Jan 27 '22 at 17:59
  • 2
  • 1
    Does the linked post solve your problem? – Zanna Feb 02 '22 at 07:16
  • 1
    Starting a systemd unit shouldn't block udev, so that's how you should do it instead of messing around with sleep and nohup. – muru Feb 02 '22 at 12:12
  • 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. – fuzzydrawrings Feb 02 '22 at 18:33
  • 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. – Jobesmor Feb 08 '22 at 14:55

0 Answers0