Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED] Refer to ANY USB flash drive in bash script

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
pmilne



Joined: Fri Jul 22, 2005 9:03 pm
Posts: 18

PostPosted: Wed Nov 20, 2013 1:19 pm    Post subject: [SOLVED] Refer to ANY USB flash drive in bash script Reply with quote

We have a script to display slideshows in LibreOffice using Raspberry pi's running raspbian - the script refers to a specific file located on the SD card. It loads the file into LO and displays it. How would I refer to the file if it were located on ANY USB flash drive attached to the pi. There's lots of advice on referring to specific drives using UDEV rules, is there a way to detect and refer to any flash drive that was plugged in? I would know the filename and it's location on the drive but not the drive details in advance.

Here's the project https://github.com/milnepe/slideshow

Thanks in advance, Pete


Last edited by pmilne on Wed Nov 20, 2013 10:57 pm; edited 1 time in total
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8457
Location: Warrington, UK

PostPosted: Wed Nov 20, 2013 1:57 pm    Post subject: Reply with quote

udev rules can run a script, s you could have a scriot that is run when a device meets the basic requirements, USB and removable, that mounts each partition and checks for the specific file. Then it either passes the file to LO or unmounts the device.

Alternatively, if you hav control over the USB flash drives used, you can give a specific label to any filesystem containing the file you need and have udev check for that label.

Either way, be aware that udev blocks while it is running a script, so your script should detach.
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
pmilne



Joined: Fri Jul 22, 2005 9:03 pm
Posts: 18

PostPosted: Wed Nov 20, 2013 3:55 pm    Post subject: Reply with quote

Thanks for the sound advice nelz - I've been meaning to get to grips with udev rules for a while! I know you've done articles on this before which I find very useful to help me on the learning curve.

I was going to run a script which checks for the file at /mnt/flashdrive/slideshow and then loads that. The path being generated by the rule, rather than the udev rule running the script but that's got me thinking.
Back to top
View user's profile Send private message
pmilne



Joined: Fri Jul 22, 2005 9:03 pm
Posts: 18

PostPosted: Wed Nov 20, 2013 10:54 pm    Post subject: Reply with quote

I created the following udev rule which seems to work for my fat formatted sticks:
KERNEL=="sd*", ATTR{removable}=="1", DRIVERS=="usb-storage", SYMLINK+="usbstick"

And made an entry in fstab:
/dev/usbstick /media/usbstick vfat defaults 0 0

This will mount the usb stick on rebooting the pi so my script can check for the presence of a known filename in /media.usbstick/slideshow.odp and read the file.
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8457
Location: Warrington, UK

PostPosted: Wed Nov 20, 2013 11:46 pm    Post subject: Reply with quote

That will work fine as long as you only ever connect one USB storage device at a time, and that has the file you need on the first partition, and that partition contains a FAT filesystem.
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast