Execute on USB insert

From ArchWiki
Revision as of 22:04, 14 December 2010 by Gogodidi (Talk | contribs) (Notes)

Jump to: navigation, search

Suppose you want to execute a certain program on the insertion of a usb dongle. Personally, I added this feature because I was getting frustrated with the computer locking up and all keyboard and mouse input was lost (The sysrq keys were not working).

There is an added security feature so that only dongles with the correct key can run the program.


Put a copy of the [[Execute_on_usb_insert#exdongle_script|Template:Filename script]] (given below) in your path.

Add the following line to your udev USB mount rule (Modify to fit your configuration):

 ACTION=="add", RUN+="/usr/bin/exdongle run /media/%k-%E{dir_name}"

Run the configuration option, for example


This sets the configuration to a random key value (only programs with the correct keys can be run on the computer), and the runtime priority to -10.

Setting up a USB dongle

First, write a script that you want to run when the dongle is inserted.

For example:


Now run the new option:

 exdongle new <Dongle mount point> test.sh

Now, whenever you insert the dongle, a root shell will be opened under the X server running on display :0. This may be useful for some administrative purposes.


There may be security issues with this, and it is probably best used for a personal computer.

exdongle script



Some notes:

  • The programs/scripts used should be self contained, the only file treated is the one passed.