udev

udev

commands

# monitor changes (optional)
udevadm monitor
 
# get device info (optional)
udevadm info -a -p $(udevadm info -q path -n /dev/sdb1)
 
# usb info
sudo lsusb -v
 
# device info
udevadm info --query=all --name=/dev/sdc1
 
udevadm control --reload-rules && udevadm trigger
 
udevadm control --reload-rules; udevadm trigger --attr-match=subsystem=block -v
 
udevadm control --reload-rules
 
udevadm trigger --attr-match=subsystem=net

Autostart script from USB device with Udev

Stage 1: Create Udev rule
<?php
$URL="http://dl.panticz.de/udev/autorun/70-persistent-usb_autorun.rules";
echo "sudo wget $URL -O /etc/udev/rules.d/70-persistent-usb_autorun.rules";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

Stage 2: Create autorun wrapper
<?php
$URL="http://dl.panticz.de/udev/autorun/usb_autorun.sh";
echo "sudo wget $URL -O /usr/sbin/usb_autorun.sh";
echo "\n";
echo "sudo chmod a+x /usr/sbin/usb_autorun.sh";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

Stage 3: Create autorun.sh script on your USB device (example)
<?php
$URL="http://dl.panticz.de/udev/autorun/autorun.sh";
echo "cd /media/YOUR_USB_DEVICE";
echo "\n";
echo "wget $URL -O ./autorun.sh";
echo "\n";
echo "chmod a+x ./autorun.sh";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>