Auto copy from usb

Yes, I was thinking the same thing…

But: /media/ appears only AFTER autocopy.sh has been executed.
So, I suppose I need 2 script:
autocopy.sh:

/bin/bash /home/osmc/autocopy2.sh &

autocopy2.sh:

<the real script, for loop, etc…>

This way I can put autocopy2 in background, letting autocopy ends immediately and so does usb folder inside /media

But I’m not sure this is the right way…

EDIT: obviously, it doesn’t work: autocopy2.sh doesn’t go to background… so autocopy is waiting to autocopy2 to finish… but usb folder in /media doesn’t appear till autocopy ends
So the real script (autocopy2) doesn’t found usb folder to copy.

Ok, headache is on the way…

Well, there’s always udisks glue Udev rule - run script when USB mounted - #3 by HibiscusKid

:joy::joy:

ok, one thing at a time.

Maybe, I’ve found the right way: I’ve installed “at” and modified autocopy.sh this way:
at now -f /home/osmc/autocopy2.sh

Now, autocopy2 seems to go to background

I’ve put my pendrive (with a file in TO_COPY folder) and after 10 seconds (sleep) the file has been copied to /home/osmc/Pictures

:tada::confetti_ball::tada::confetti_ball::tada::confetti_ball::tada::confetti_ball:

EDIT: I forgot, the autocopy2.sh:

#!/bin/bash
sleep 10
src=/media
dst=/home/osmc/Pictures/
for srcfile in ${src}/*/TO_COPY/*.*; do
	cp "$srcfile" "$dst"
done

I’d suggest you include the -n (no-clobber) flag, so you only copy those files that don’t exist on the destination.

Thanks, script updated.
Any other suggestions are welcome