I found this http://www.unix.com/shell-programming-a ... evice.html however I have been unable to compile autorun http://linux.softpedia.com/get/Utilitie ... 5250.shtml has anyone ever tried this?. I want to autostart office when I plugin the USB stick.
Thanks
Rafael Alcocer
Autostarting an application just by inserting USB Stick
- brokenman
- Site Admin
- Posts: 6105
- Joined: 27 Dec 2010, 03:50
- Distribution: Porteus v4 all desktops
- Location: Brazil
Re: Autostarting an application just by inserting USB Stick
Here is how I do it. I will assume your USB is plugged in at lies at: /dev/sdb1
Get the model of your USB.
ATTRS{model}=="silicon-power "
Create a udev rule that will run a script on plugin.
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z]1", ATTRS{model}=="silicon-power ", RUN+="/usr/local/bin/run.sh"
Create the script to run:
#!/bin/bash
touch /tmp/touched.txt
Make it executable:
Reload your udev rules.
Unmount your device. Remove it. Plug it back in and see that your script has run.
Be responsible. Don't anything stupid for example like put a porn video on your friends copy of porteus and run a script that launches it at full volume. It doesn't end well.
Get the model of your USB.
Code: Select all
udevadm info -a -n sdb1 | grep model
Create a udev rule that will run a script on plugin.
Code: Select all
cat /etc/udev/rules.d/98-usb-run.rules
Create the script to run:
Code: Select all
cat /usr/local/bin/run.sh
touch /tmp/touched.txt
Make it executable:
Code: Select all
chmod +x /usr/loca/bin/run.sh
Code: Select all
udevadm control --reload-rules
Be responsible. Don't anything stupid for example like put a porn video on your friends copy of porteus and run a script that launches it at full volume. It doesn't end well.

How do i become super user?
Wear your underpants on the outside and put on a cape.
Wear your underpants on the outside and put on a cape.
- brokenman
- Site Admin
- Posts: 6105
- Joined: 27 Dec 2010, 03:50
- Distribution: Porteus v4 all desktops
- Location: Brazil
Re: Autostarting an application just by inserting USB Stick
If you are running anything other than a console job you may run into trouble. Probably due to the dbus communication and no display. I just saw that you are wanting to run office so follow this instead.
I found this method a while back for popping up a notification when plugging in a USB. It requires creating three files.
1. A udev rule
2. A dbus workaround script
3. Your main script to run
File 1: /etc/udev/rules.d/98-usb-run.rules
File 2: /usr/local/bin/dbus-workaround.sh
File 3: /home/guest/runguest.sh
Using this I get a popup message through notify-send when I plug in. Just replace the bit about running notify-send with your GUI and you are good to go.
Again, on a serious note. Be aware of the HUUUGE security implications here.
I found this method a while back for popping up a notification when plugging in a USB. It requires creating three files.
1. A udev rule
2. A dbus workaround script
3. Your main script to run
File 1: /etc/udev/rules.d/98-usb-run.rules
Code: Select all
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z]1", ATTRS{model}=="silicon-power ", RUN+="/home/guest/runguest.sh 'Important community announcement' 'Somebody just stuck something in your port!'"
Code: Select all
#!/bin/sh
user=guest
pids=`pgrep nm-applet`
title=$1
text=$2
timeout=$3
icon=$4
xhost local:guest
export DISPLAY=:0.0
if [ -z "$title" ]; then
echo You need to give me a title >&2
exit 1
fi
if [ -z "$text" ]; then
text=$title
fi
if [ -z "$timeout" ]; then
timeout=60000
fi
for pid in $pids; do
# find DBUS session bus for this session
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
/proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
# use it
#icon hack:
if [ -z $icon ]; then
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
notify-send -u low -t $timeout "$title" "$text"
else
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
notify-send -u low -t $timeout -i "$icon" "$title" "$text"
fi
done
Code: Select all
sudo -u guest /usr/local/bin/dbus-workaround.sh "$1" "$2" 6000
Again, on a serious note. Be aware of the HUUUGE security implications here.
How do i become super user?
Wear your underpants on the outside and put on a cape.
Wear your underpants on the outside and put on a cape.
- brokenman
- Site Admin
- Posts: 6105
- Joined: 27 Dec 2010, 03:50
- Distribution: Porteus v4 all desktops
- Location: Brazil
Re: Autostarting an application just by inserting USB Stick
Out of interest I wanted to see. I have reduced it to the following:
File 1: /etc/udev/rules.d/98-usb-run.rules
File 2: /home/guest/runguest.sh
That's all that is needed. The important part is the DISPLAY variable being exported, and running the GUI app as guest.
File 1: /etc/udev/rules.d/98-usb-run.rules
Code: Select all
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z]1", ATTRS{model}=="silicon-power ", RUN+="/home/guest/runguest.sh"
Code: Select all
#!/bin/bash
xhost local:guest
export DISPLAY=:0.0
sudo -u guest /usr/bin/gnome-mplayer
How do i become super user?
Wear your underpants on the outside and put on a cape.
Wear your underpants on the outside and put on a cape.