Here's the solution that I came up with for my own problem. When the AC595U USB modem is inserted, the SYSFS properties for vendor and product are checked, the new device is called ac595u0,1,2 (or whatever numbers are assigned). The modem.agent script runs with "add" as the argument, and a symlink is created from /dev/modem to whatever the first ac595u device is (ac595u0 if there are no other ttyUSB devices, but this will change if there *are* other ttyUSB devices).
Upon removal (of any ttyUSB device), the modem.agent is executed with "del" as the argument and if no ac595u devices exist, the /dev/modem symlink is removed.
my new udev rules:
Code:
KERNEL=="ttyUSB*", ACTION=="add", SYSFS{idVendor}=="1199", SYSFS{idProduct}=="0120", NAME="ac595u%n", RUN+="modem.agent add"
KERNEL=="ttyUSB*", ACTION=="remove", RUN+="modem.agent del"
The modem.agent script (lives in /lib/udev and must be executable):
** Note: to test this on the command line, change "print $10" to "print $9". For whatever reason, when using awk in a script called from udev, the argument list is increased by 1 **
Code:
#!/bin/bash
if [ $# -gt 0 ]; then
MODEM=`ls -l /dev/ac595u* | head -1 | awk '{ print $10 }'`
if [ "$1" = "add" ]; then
if [ -n "$MODEM" ]; then
ln -sf $MODEM /dev/modem
fi
elif [ "$1" = "del" ]; then
# ac595u device found?
if [ ! -n "$MODEM" ]; then
# device not found - check for modem symlink
if [ -L /dev/modem ]; then
# remove link to modem
rm /dev/modem
fi
fi
fi
fi