title: Ubuntu Server 21.10 - How to run Shell Script when plugging USB device
body: <p>I would like to run a specific script when plugging a USB device. But, nothing happens when I a USB device.</p>
  <p>Here is the script I would like to run ( <code>/home/update.sh</code> ):</p>
  <pre><code>#!/bin/sh
  netplan apply
  </code></pre>
  <p>In the same directory, I made it executable by running:</p>
  <pre><code>sudo chmod +x update.sh
  </code></pre>
  <p>I updated the udev rule file ( <code>/etc/udev/rules.d/70-snap.snapd.rules</code> ) by adding the following line after <code>LABEL=&quot;mm_mbm_check&quot;</code> :</p>
  <pre><code>ACTION==&quot;add&quot;, ATTRS{idVendor}==&quot;`****`&quot;, ATTRS{idProduct}==&quot;`****`&quot;, RUN+=&quot;/home/update.sh&quot;
  </code></pre>
  <p>As far as I understand, I'm using the * to allow any usb device.</p>
  <p>After updating this udev rule file, I run the following script to apply the rules:</p>
  <pre><code>sudo service udev restart
  </code></pre>
  <p>Here is the log from syslog after running the restart udev command ( <code>tail -f /var/log/syslog</code> ):</p>
  <pre><code>Nov  8 19:52:20 ubuntu systemd-udevd[23328]: /usr/lib/udev/rules.d/90-pi-bluetooth.rules:14 Invalid value &quot;/bin/sh -c 'ALIASES=/proc/device-tree/aliases; if cmp -s $ALIASES/uart0 $ALIASES/serial0; then echo 0;elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then echo 1; else exit 1; fi'&quot; for PROGRAM (char 58: invalid substitution type), ignoring, but please fix it.
  Nov  8 19:52:20 ubuntu systemd-udevd[23328]: /usr/lib/udev/rules.d/90-pi-bluetooth.rules:27 Invalid value &quot;/bin/sh -c 'ALIASES=/proc/device-tree/aliases; if [ -e /dev/ttyAMA0 ]; then exit 1; elif cmp -s $ALIASES/uart0 $ALIASES/serial0; then echo 0;elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then echo 1; else exit 1; fi'&quot; for PROGRAM (char 97: invalid substitution type), ignoring, but please fix it.
  Nov  8 19:52:20 ubuntu systemd-udevd[23328]: /usr/lib/udev/rules.d/90-pi-bluetooth.rules:38 Invalid value &quot;/bin/sh -c 'ALIASES=/proc/device-tree/aliases; if cmp -s $ALIASES/uart1 $ALIASES/serial0; then echo 0; elif cmp -s $ALIASES/uart1 $ALIASES/serial1; then echo 1; else exit 1; fi '&quot; for PROGRAM (char 58: invalid substitution type), ignoring, but please fix it.
  </code></pre>
  <p>Finally, when I plug the USB device to the Raspberry, nothing happens.</p>
  <p>My configuration:</p>
  <ul>
  <li>Raspberry Pi 3</li>
  <li>Ubuntu Server 21.10</li>
  </ul>
  <p>Thanks for your help !</p>