I want to detect with a bash script when a joypad is plugged in and retrive the ID_MODEL of the controller in a variable.
So the script should remain silently listening as long as it is plugged in a joypad (no hdd or other peripherals) and then it must execute some commands.
Even after the joypad in plugged, the script should continue listening if other joypads are plugged in and then it should execute the same commands as before with the new joypad.
I only can detect the joystick already plugged in with:
#!/bin/bash
# Get the name and id of the joystick
name=$(udevadm info --query=all --name=/dev/input/js0 | grep ID_MODEL= | awk -F= '{print $2}')
# Print the name and id of the joystick
echo "Joystick detected: Name=$name"
But i'm stuck at beginning of the script: I don't know how to make it stays listening if a joypad is inserted.
Im using Raspbian GNU/Linux 10 (buster)
Thanks