Automatic Activation, Hotplug and UDEV, Configuration
Post Reply
claes508
Posts: 7
Joined: 07 Dec 2011, 10:44

Start script on switch success

Post by claes508 » 07 Dec 2011, 12:54

Hello,

Sorry if this is a simple question. I want to start my own script after a successful switch. How should I do it? I would like to avoid tampering with udev rule so it get overwritten on next update.

:shock: Classee

Josh
Site Admin
Posts: 6593
Joined: 03 Nov 2007, 00:30

Post by Josh » 07 Dec 2011, 21:42

That should not be too hard.

You can easily add your own udev rule file, like 90-my.rules or whatever, to the rules folder; it will never be overwritten.
In the file, check for the target ID, just like the usb_modeswitch rules do for the default IDs.

You can copy the line that says SYSTEM!="usb" ....
Don't use the line that checks the interface class.
Copy the line with the end marker (to the end, obviously).
Both lines make sure that your rule is only tested when a USB device is ADDED or CHANGED.

You should be able to run all kinds of programs with the RUN parameter, but be aware that the environment for programs run by this is very limited. So you have to provide PATH and others in the script.


claes508
Posts: 7
Joined: 07 Dec 2011, 10:44

Post by claes508 » 08 Dec 2011, 16:22

Josh wrote:That should not be too hard.

You can easily add your own udev rule file, like 90-my.rules or whatever, to the rules folder; it will never be overwritten.
In the file, check for the target ID, just like the usb_modeswitch rules do for the default IDs.

You can copy the line that says SYSTEM!="usb" ....
Don't use the line that checks the interface class.
Copy the line with the end marker (to the end, obviously).
Both lines make sure that your rule is only tested when a USB device is ADDED or CHANGED.

You should be able to run all kinds of programs with the RUN parameter, but be aware that the environment for programs run by this is very limited. So you have to provide PATH and others in the script.
Hi,

That sounds like a good idea. Same structure as your /lib/udev/rules.d/40-usb_modeswitch.rules

Code: Select all

ACTION!="add", GOTO="modeswitch_rules_end"
SUBSYSTEM!="usb", GOTO="modeswitch_rules_end"

LABEL="modeswitch_rules_begin"  ## not needed in this simple case...
# Huawei E173
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1436", RUN+="myscript"
# ... more modems ...

LABEL="modeswitch_rules_end"

Josh
Site Admin
Posts: 6593
Joined: 03 Nov 2007, 00:30

Post by Josh » 08 Dec 2011, 21:49

Mind that if your program is relying on the connectivity that the modem provides, you may want to add a delay ("sleep") to your script. It is likely that the setup will take a moment after the "new" device appeared.

But you probably knew that already ...




claes508
Posts: 7
Joined: 07 Dec 2011, 10:44

Post by claes508 » 09 Dec 2011, 17:15

Yes, definitely :D

A Sleep 10 should suffice, and then run my modem checks and preparations; ATZ0, AT+CSQ, ATI and make sure PIN is correct.

Post Reply