8

On Ubuntu 14.04 I have a long running bash script with a simple udev rule that works perfectly like this:

ACTION=="change", SUBSYSTEM=="block", RUN+="/opt/script.sh"

On Ubuntu 16.04 things aren't going so well. The script starts to run but then gets killed before it completes. I then tried changing my udev rule to call a warapper script which would detach the script. I tried:

#!/bin/sh
nohup /opt/script.sh  &

Then I tried:

#!/bin/sh
/opt/script.sh | at now

To no avail.

I then tried to create a systemd service...

ACTION=="change", SUBSYSTEM=="block", ENV{SYSTEMD_WANTS}=="justrunthescript.service"

/etc/systemd/system/justrunthescript.service

[Unit]
Description=Just run the script

[Service]
ExecStart=/opt/script.sh

Which I got to run the script at some point, but my script relies on udev parameters like $ID_FS_TYPE which don't get passed in this way.

I think what I want is pretty simple, just insert a disc and run my script from a udev rule and don't kill the script. What's the best way to go about this?

derHugo
  • 3,376
  • 5
  • 34
  • 52

1 Answers1

7

Realized I needed to do:

 #!/bin/sh
 echo /opt/script.sh | at now