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'
bash other.sh & disown
– matigo Jan 27 '22 at 15:16udev
manualRUN{type}
– Jan 27 '22 at 17:59at now -f scrip2.sh
to launch the other script. That won't blockudev
either. OP says he needs the 20 second delay for whatever reason, so havingscrip2.sh
start withsleep 20
would work without requiring a systemd.service
entry. – fuzzydrawrings Feb 02 '22 at 18:33