سؤال

I am using the software Motion on my Raspberry Pi (Ubuntu) to connect to my network security camera. When this camera detects movement, it dumps JPGs every second into a /tmp/camera folder on this Ubuntu machine.

Motion allows you to run a custom Bash script either after each picture is saved (ever second) or after movement has stopped (at the end of all pictures).

What I want is to send these images to my phone (and eventually FTP them too). Currently, I am using the option to run a script on EVERY picture save, using 'mail' on Ubuntu to attach the recently saved file. This doesnt work very well because one 'movement' might have 10 image frames, which means I get 10 different emails.

This current script is simply: on_picture_save echo "Motion Detected at %Y-%m-%d %T" | mail -a %f -s "Subject user@example.com

So I was thinking I need a custom Bash script that I set to run at the end of the motion being detected. It needs to attach all JPGs from a given folder, (not zipped or I wont be able to see them on my mobile email client) and then email them to a given address.

Is there a way to loop through all JPGs in a given folder and attach to a single email? is it possible to make sure that nullmailer or mail actually sent the images correctly before deleting them locally (or moving them to another folder to be deleted later)

Could this same script ZIP and ftp the set of images at the same time?

Any help would be greatly appreciated.

هل كانت مفيدة؟

المحلول

Here's an offsite answer that might help you: http://johnstanfield.com/?p=683

While the author of that page knew exactly how many attachments he wanted to use in his email, it seems that you do not and so his final answer (do a bunch of uuencode commands concatenated by && and then pipe that to mail) may be not be the best fit for you. But take a look at his second answer:

uuencode file1 first_file >> uu.txt
uuencode file2 second_file >> uu.txt
cat uu.txt | mail -s "a bunch of files" me@mydomain.com
rm uu.txt

You could easily replace the first two lines with a for loop that creates uu.txt with every file in /tmp/camera:

for file in `ls /tmp/camera`; do
  uuencode $file dummyname >> attachments.txt
done

cat attachments.txt | mail -s "Motion Capture Images" me@mydomain.com

As for zipping, that too would be easily accomplished:

cd /tmp/camera
tar czvf MotionCapture.tar.gz *.jpg #or replace jpg with your images' file extension

FTP might be a little more difficult because of its interactivity. I don't have much experience with it, so I'll just point you here: http://kb.iu.edu/data/afqg.html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top