New user's registration have been closed due to high spamming and low trafic on this forum. Please contact forum admins directly if you need an account. Thanks !

Automatic digital camera capture

Good ideas? Share with us!
Post Reply
ctc
Posts: 4
Joined: 29 Dec 2009, 17:31

Automatic digital camera capture

Post by ctc »

Hi,

I have got an idea what to use my Bubba for. The idea was inspired by this great tip:
http://forum.excito.net/viewtopic.php?f=8&t=1609

I would like to have this feature:
When I connect my memorycard from my digital camera this should happen:
1. Automatic connect(mount) the drive, I connect for example a SD card via an USB memory card reader.
2. Depending on what memery card I inserted, a copy if certain files (for examples JPG, AVI, NEF etc) should be copied to preset directories.
3. The drive should then be automatically unmounted, ready to remove from the usb reader.
4. An e-mail should be sent to bubba itself with a report of the copy process. I have an Nokia phone connected to Bubbas e-mail system via IMAP and would then instantly get an email with the result. If I see that the copy operation was sucessfull, I could remove the SD card, insert it into my camera again and format it.

The big benefit is that I don't need to start my PC to copy the files manually. Bubba would do it automatically.

Whould that be possible to do? I'm not a Linux expert, but is thinking of making a try.

/Clarence
RandomUsername
Posts: 904
Joined: 09 Oct 2009, 18:49

Re: Automatic digital camera capture

Post by RandomUsername »

I've done something very similar - when I connect my digital video camera to my B2 it mounts it and copies all the video files to a temp directory in /home/storage/ where I can then organise the files.

Most of what you need is the in post you linked to.

One thing, I don't know if it's a quirk with the Bubba or my camera but for some reason, when I connected the camera the Bubba detected it as multiple devices being connected and udev launched my script 13 times! I built a lock file type mechanism into the script so only one instance can run at a time.

Here's my script if it helps, you just get udev to detect your device and launch it. I'm not the best coder so I'm sure there are ways I could things better but it works for me:

Code: Select all

#!/bin/bash
#This line creates a variable based on the current date and time.
DATE=`date +%y%m%d%H%M%S`

#If this file exists, future attempts to run this script will simply exit.
LOCKFILE=/var/lock/getmovs.lock

#The location I want the movie files copied to. The $DATE part refers to the variable above. Having the directory uniquely named like this should hopefully prevent files being accidentally overwritten.
TEMPDIR=/home/storage/temp/files_$DATE

#The location I want my camera mounted to. This directory was created by the B2 the first time I connected the camera so I use it to avoid confusion.
MOUNT=/home/storage/extern/GZ-MG40-1

#############################################################

#Looking for the lockfile.
if [ ! -e $LOCKFILE ];
( set -o noclobber; echo "$$" > "$LOCKFILE") 2> /dev/null; 
then
#Removes the lockfile in the event the script is killed before it completes - just cleaning up after itself.
   trap 'rm -f "$LOCKFILE"; umount $MOUNT; exit $?' INT TERM EXIT
sleep 5
#Creating the temp directory
mkdir /home/storage/temp
mkdir $TEMPDIR
#Mounting the camera
mount /dev/sdb1 $MOUNT
#Copying the files.
cp -r $MOUNT/* $TEMPDIR
sleep 5
#Dismount the camera, remove the lockfile.
umount $MOUNT
   rm -f "$LOCKFILE"
   trap - INT TERM EXIT
else
exit;
fi
exit;
ctc
Posts: 4
Joined: 29 Dec 2009, 17:31

Re: Automatic digital camera capture

Post by ctc »

@RandomUsername: Thanks for sharing your code! I'm not an expert in bash scripting but will try your code.

Now I just need to figure out how to send an e-mail from the script... Does anybody know how?

Thanks
Clarence
Post Reply