Set Motion as e-mailing Security Camera

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
kukamuumuka

Set Motion as e-mailing Security Camera

Post by kukamuumuka »

1. Install Mutt email program

Code: Select all

sudo apt-get install mutt
2. Make a .muttrc file

Code: Select all

pluma ~/.muttrc
... the contents

Code: Select all

set imap_user = from_my@gmail.com
set imap_pass = verygoodpasswordhere

set smtp_url = smtp://from_my@smtp.gmail.com:587/
set smtp_pass = verygoodpasswordhere
set from = from_my@gmail.com
set realname = seuritycamera

set folder = imaps://imap.gmail.com:993
set spoolfile = "+INBOX"
set postponed="+[Gmail]/Drafts"

set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates

set move = no
set record = '+Sent'
3. Test Mutt before installing Motion and then install Motion

Code: Select all

sudo apt-get install motion
Add yourself to the motion group

Code: Select all

sudo adduser myself motion
Configure Motion

Code: Select all

gksu pluma /etc/default/motion
... the contents

Code: Select all

# set to 'yes' to enable the motion daemon
start_motion_daemon=yes

Code: Select all

gksu pluma /etc/motion/motion.conf
... edit these lines

Code: Select all

--------------------------------
# Minimum time in seconds between capturing picture frames from the camera.
# Default: 0 = disabled - the capture rate is given by the camera framerate.
# This option is used when you want to capture images at a rate lower than 2 per second.
minimum_frame_time 1
--------------------------------
# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
target_dir /path/motion
--------------------------------
# Command to be executed when a motion frame is detected (default: none)
on_motion_detected cd /home/username && ./.startup.sh
--------------------------------
4. Make a startup script

Code: Select all

pluma ~/.startup.sh
... the contents

Code: Select all

#! /bin/sh
sleep 40 && cd /home/username && ./.mutt.sh 
Make the script executable

Code: Select all

chmod a+x /home/username/.startup.sh
5. Make video + email script

Code: Select all

pluma ~/.mutt.sh
... the contents

Code: Select all

#! /bin/sh
TIMESTAMP=$(date +%Y%m%d%H| sed 's/ //g')

find /path/motion -iname "*.swf" -exec mv {} /path/allvideos \; && sleep 30 && genisoimage -o /path/toemail/video$TIMESTAMP.iso /path/allvideos && mutt -z -a /path/toemail/video$TIMESTAMP.iso -s “Security_videos”  -- to_some_email@gmail.com from_my@gmail.com < /dev/null 
Tip: There must not be cap in the message "message_here" in the mutt line.
Make the script executable

Code: Select all

chmod a+x /home/username/.mutt.sh
Make three folders
/path/motion
/path/allvideos
/path/toemail

Set the permissions for the folders

Code: Select all

sudo chmod 775 /path/foldername
6. Add Motion to the startup applications and or crontab

PS. emails comes always when Motion has react!
PS2. Install Gnash for watching swf-videos.

Code: Select all

sudo apt-get install gnash
Last edited by kukamuumuka on Tue Jun 30, 2015 7:04 am, edited 4 times in total.
JusTertii

Re: Set Motion as e-mailing Security Camera

Post by JusTertii »

Excellent how-to, good sir! Thank you. Very nicely laid out, easy to follow.

Just one (small) thing -- do you mean crontab, rather than contab?
kukamuumuka

Re: Set Motion as e-mailing Security Camera

Post by kukamuumuka »

JusTertii wrote:Excellent how-to, good sir! Thank you. Very nicely laid out, easy to follow.

Just one (small) thing -- do you mean crontab, rather than contab?
Yes of course. My typo .. :oops:
Thank you for correction .. :D
phd21
Level 20
Level 20
Posts: 10104
Joined: Thu Jan 09, 2014 9:42 pm
Location: Florida

Re: Set Motion as e-mailing Security Camera

Post by phd21 »

Hi administrollaattori,

Nice tutorial.

As a user of "Motion", I was wondering if "Motion" would email updates if you just edited the motion configuration file to add email settings without having to setup anything else? Thanks..
Phd21: Mint 20 Cinnamon & KDE Neon 64-bit Awesome OS's, Dell Inspiron I5 7000 (7573, quad core i5-8250U ) 2 in 1 touch screen
kukamuumuka

Re: Set Motion as e-mailing Security Camera

Post by kukamuumuka »

phd21 wrote: As a user of "Motion", I was wondering if "Motion" would email updates if you just edited the motion configuration file to add email settings without having to setup anything else? Thanks..
There is a lot of choices to use Motion, and with e-mails can use many different ways. Anyway using Mutt as an email program, is the most easiest way to send emails.
https://wiki.debian.org/Mutt

For determining the address to send email, you simply write that address to the Mutt´s command.

Code: Select all

mutt -z -a “hello” somefile -- recipient@gmail.com sender@gmail.com < /dev/null 
kukamuumuka

Re: Set Motion as e-mailing Security Camera

Post by kukamuumuka »

Motion can use as live monitoring camera via browser also. Make a html-file and add the right path

Code: Select all

<!DOCTYPE html>
 <html>
 <head>
 <style type="text/css">
 body { 
 text-align:center;
 background-color:#000000;
 }
 .container {
 width:100%;
 }
 .motion {
 border: 0;
 width: 90%;
 height: auto;
 }
 .clear {
 clear:both;
 }
 </style>
 </head>
 <body>
 <a href="http://localhost:8081"><img class="motion" src="http://localhost:8081" /></a>

 </body>
 </html>
Post Reply

Return to “Tutorials”