Linux – Automounting SD card when inserted in Ubuntu

bash-scriptinglinuxsd cardshell-scriptubuntu 12.04

I am trying to write a BASH script that automounts an SD card once it is inserted in the card reader, then move all pictures to a folder in the HDD and renaming each file to the date and time the picture was taken at.

Any ideas how to achieve that? I am using Ubuntu 12.04 with no GUI Thanks 🙂

Best Answer

Just to provide a full answer for you:

Auto mount and copy over data

Advanced Way (how you should do it)

You will want to use UDEV rules that are specific to the UUID of your device (pardon my above type of udid).

Lazy Way (how you could do it)

Run a CRON Job to execute your script at a specified interval. You would obviously need the script to verify that the SD is plugged in and/or mounted before executing the rest).

Rename / Move

To get EXIF data

$ identify -verbose imageFile.jpg

That spits out loads of goodies, so let's suppose you want the creation date from that - let's filter that down:

$ identify -verbose imageFile.jpg | awk '/exif:/' (or grep exif)


OP requested another method in the comments:

You are asking to nest folders instead, for example November 20, 2012 would be ~/2012/11/20/*.jpg's

Here is the script I made to try this, it works with EXIF now (the initial items for you were based on creation date, which would be floating as you move or copy the file). It's hosted on my blank site for you and I will post a screenshot too (since it's a lot of effort to make it formatted here).

I would recommend you test this on a limited scale before implementing it. I put in Command Line Args for testing, so I was doing ~/Pictures to ~/Documents (although it prefers the full path)

Related Question