Alexandre34
Posts: 21
Joined: Sun Jan 31, 2016 6:18 am

autorun script on usb stick

Wed Apr 20, 2016 1:37 pm

I am trying to solve this problem, but I need help:
I want to run a script (a simple cp script to copy the files from a folder of the usb stick to the home directory) every time an usb stick is inserted.
I use raspian jessie and lxde.
I have try to add this rule in /etc/udev/rules.d/100.mymount.rules

Code: Select all

ACTION=="add", SUBSYSTEM=="block", RUN+="/home/pi/testauto.sh"
but it does not work. So I need help on 3 points:
1) How to execute a script when usb drive is insert (we only have the label of the drive, not the IDs)
2) How to disable the dialog that is showned in LXDE when a new drive is mounted ? (see picture)
3) How to change the action to take when LXDE find a new drive ? (see picture)
automount.png
automount.png (18.6 KiB) Viewed 2661 times

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: autorun script on usb stick

Wed Apr 20, 2016 2:45 pm

Alexandre34 wrote: I want to run a script (a simple cp script to copy the files from a folder of the usb stick to the home director
I don´t think that is really what you want... what if the files are already there? what if its a unique usb and you have an exception? ... there are other points too...
Alexandre34 wrote: I have try to add this rule in /etc/udev/rules.d/100.mymount.rules

Code: Select all

ACTION=="add", SUBSYSTEM=="block", RUN+="/home/pi/testauto.sh"
but it does not work.
Ok, so what happens instead; look at your logs, in /var/log
Also, does the script run ´manually´ after you plug in the usb and it correctly mounts?
Are you having trouble getting the script to run, or are you having trouble mounting the drive?
marcus
:ugeek:

Alexandre34
Posts: 21
Joined: Sun Jan 31, 2016 6:18 am

Re: autorun script on usb stick

Fri Apr 22, 2016 7:36 am

Finally, after some hours fighting with rules and log, I give up...

I wrote a basic script testing if the sitck is inserted:
#!/bin/bash
# autocopy.sh
# Written by Alexandre GESP pour ACE ELECTRONIQUE
while true; do
if [ -d "/media/pi/TRANSFERT" ]; then
# Control will enter here if $DIRECTORY exists.
count=$(ls 2>/dev/null -Ub1 -- /media/pi/TRANSFERT/*.ACE | wc -l)
if [ $count -gt 0 ]; then
echo $count fichiers trouves
sudo rm /home/pi/ftp/* 2>/dev/null
sudo mv /media/pi/TRANSFERT/ftp/* /home/pi/ftp 2>/dev/null
fi
fi
sleep 10
done
Not very smart, but it works....

Return to “Beginners”