User avatar
LightningPi
Posts: 24
Joined: Wed Mar 26, 2014 3:00 am

Re: Send an email when a file is created

Mon Jun 29, 2015 11:00 pm

So your supposed to change this part of the code:
# Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
# To give the filename as an argument to a command append it with %f
; on_movie_end value
right?
If so, are you supposed to remove the semicolon in front?
and change it to this:
# Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
# To give the filename as an argument to a command append it with %f
; on_movie_end echo ‘Webcam Alert’ | mail -a %f -s “Webcam Alert” youremail@youremailprovider.com
- LightningPi(a.k.a LightningJimmy)

Tom_A
Posts: 272
Joined: Fri Dec 06, 2013 8:34 am

Re: Send an email when a file is created

Mon Jun 29, 2015 11:29 pm

Yes. Remove the semicolon in front. It has the same effect as the "#" marks, telling the line not to be run. This is handy if you change your mind and want to disable sending photos or videos but think you might change your mind again. You can leave the whole line in and comment it out when you want it turned off. You need to reload motion for it to be applied though. Make sure the email address is the address you want to send to and you're set!

If you send video, you might need to experiment with the different formats to see which one plays well in the video player you are using. I find that I have to use VLC on my iPhone to get videos to play back.

User avatar
LightningPi
Posts: 24
Joined: Wed Mar 26, 2014 3:00 am

Re: Send an email when a file is created

Tue Jun 30, 2015 12:16 am

It sends emails manually but not when a video is created. BTW, is it made so it sends the video with it? If so, how do I disable that?

I was supposed to put
on_movie_end echo ‘Webcam Alert’ | mail -a %f -s “Webcam Alert” youremail@youremailprovider.com
in sudo nano /etc/motion/motion.conf not the console thingie, correct?
- LightningPi(a.k.a LightningJimmy)

Tom_A
Posts: 272
Joined: Fri Dec 06, 2013 8:34 am

Re: Send an email when a file is created

Tue Jun 30, 2015 2:47 am

LightningPi wrote:It sends emails manually but not when a video is created. BTW, is it made so it sends the video with it? If so, how do I disable that?

I was supposed to put
on_movie_end echo ‘Webcam Alert’ | mail -a %f -s “Webcam Alert” youremail@youremailprovider.com
in sudo nano /etc/motion/motion.conf not the console thingie, correct?
As I explained in detail "-a %f" sets it to attach the file to the email. If you remove -a (attach) and %f (the file's path) then the email will be sent when the file is created, however it will not be part of the email.

If manually is working but automatic emails are not working, then you probably have a permissions issue where the files are being saved. If you switched the directory where motion saves the files, you need to make sure motion has privileges to write to the directory where the files are saved. A sign that this is the problem is that a webcam with an activity light will turn off when motion is detected as motion messes up trying to write to a directory it is not allowed to write to.

schneidz
Posts: 22
Joined: Sat Sep 15, 2012 9:08 pm

Re: Send an email when a file is created

Tue Jun 30, 2015 4:37 pm

LightningPi wrote:I made a Raspberry Pi security camera and would like it to send me an email whenever a new video is created. The videos are saved in /home/pi/Motion and are .mpg files, if that helps. Also, I would like to find a way to delete .mpg files over 14 days old. Can someone please give me detailed instructions on how to do this?

Code: Select all

<whatever-command-used-to-record-videos>; echo new video created: `date` | mail -s "new video" user@email-addy.com

Code: Select all

crontab -e
@daily /bin/touch -d `date --date "2 weeks ago" +%Y%m%d` /home/pi/Motion/mpg.date && /bin/find /home/pi/Motion -type f -name "*.mpg" ! -newer /home/pi/Motion/mpg.date -delete

User avatar
LightningPi
Posts: 24
Joined: Wed Mar 26, 2014 3:00 am

Re: Send an email when a file is created

Tue Jun 30, 2015 4:48 pm

Sorry for asking a stupid question but, am I supposed to put "on_movie_end echo ‘Webcam Alert’ | mail -s “Webcam Alert” youremail@youremailprovider.com" in the console or in the config?
- LightningPi(a.k.a LightningJimmy)

schneidz
Posts: 22
Joined: Sat Sep 15, 2012 9:08 pm

Re: Send an email when a file is created

Tue Jun 30, 2015 5:16 pm

LightningPi wrote:Sorry for asking a stupid question but, am I supposed to put "on_movie_end echo ‘Webcam Alert’ | mail -s “Webcam Alert” youremail@youremailprovider.com" in the console or in the config?
i would assume the config since on_movie_end isnt a linux command that i heard of (not sure about the software you are using but tom seems knowledgeable). have you tried it in the console; did you get an error ?

User avatar
LightningPi
Posts: 24
Joined: Wed Mar 26, 2014 3:00 am

Re: Send an email when a file is created

Tue Jun 30, 2015 5:21 pm

Yeah, it said it wasn't a command. When I put it in the config, nothing happened. I don't know what I did wrong... I might have placed it in the wrong place or something...
- LightningPi(a.k.a LightningJimmy)

Tom_A
Posts: 272
Joined: Fri Dec 06, 2013 8:34 am

Re: Send an email when a file is created

Tue Jun 30, 2015 7:56 pm

LightningPi wrote:Yeah, it said it wasn't a command. When I put it in the config, nothing happened. I don't know what I did wrong... I might have placed it in the wrong place or something...
That is not a command. It goes in the config. If you are testing, you leave that off when you enter it into the console.
It's a variable or object in the program. You set it equal to the commands you want executed and when the program detects the events that match they are executed. The attachment will not be found if you use the command line manually since %f does not get set.

User avatar
LightningPi
Posts: 24
Joined: Wed Mar 26, 2014 3:00 am

Re: Send an email when a file is created

Tue Jun 30, 2015 8:46 pm

I know my questions are stupid, can I just put the line anywhere or does it have to be a specific place?
- LightningPi(a.k.a LightningJimmy)

Tom_A
Posts: 272
Joined: Fri Dec 06, 2013 8:34 am

Re: Send an email when a file is created

Tue Jun 30, 2015 9:14 pm

LightningPi wrote:I know my questions are stupid, can I just put the line anywhere or does it have to be a specific place?
I usually leave it wherever it originally was in the file, but usually with config files like this it doesn't matter. It makes sense to put them in an order that makes them easy to find. Be careful about setting anything twice. You might put something at the top of the file and be unable to figure out why it doesn't work when the item is being set back to something else later in the file. I didn't contribute to writing the motion software, but I'm assuming it reads through the file and sets values based on the readable lines.

User avatar
LightningPi
Posts: 24
Joined: Wed Mar 26, 2014 3:00 am

Re: Send an email when a file is created

Wed Jul 01, 2015 5:21 pm

Still doesn't work for some reason... I don't know why... Should I give you my motion config?
- LightningPi(a.k.a LightningJimmy)

Tom_A
Posts: 272
Joined: Fri Dec 06, 2013 8:34 am

Re: Send an email when a file is created

Wed Jul 01, 2015 7:29 pm

LightningPi wrote:Still doesn't work for some reason... I don't know why... Should I give you my motion config?
Where are your video/audio files being saved? What is the directory path? What are the permissions on the directory?

User avatar
LightningPi
Posts: 24
Joined: Wed Mar 26, 2014 3:00 am

Re: Send an email when a file is created

Sat Jul 11, 2015 8:36 pm

Tom_A wrote:
LightningPi wrote:Still doesn't work for some reason... I don't know why... Should I give you my motion config?
Where are your video/audio files being saved? What is the directory path? What are the permissions on the directory?
Sorry for the late response again, was working on my aquaponics project. Those are all correct, do you mind giving me the part of the motion config that sends the email? I want to see what part of mine is wrong.
- LightningPi(a.k.a LightningJimmy)

Tom_A
Posts: 272
Joined: Fri Dec 06, 2013 8:34 am

Re: Send an email when a file is created

Sun Jul 12, 2015 5:05 am

on_movie_end echo 'Webcam Alert' | mail -a %f -s 'Pleasant Webcam' youremailaddress@youremailserver.com

or

on_picture_save echo 'Webcam Alert' | mail -a %f -s 'Pleasant Webcam' youremailaddress@youremailserver.com

This depends on whether you want still pictures or movie clips. You can have both enabled at the same time if you want. You need to remove the semi-colon at the beginning of the line you want to activate.

tpylkko
Posts: 382
Joined: Tue Oct 14, 2014 5:21 pm

Re: Send an email when a file is created

Sun Jul 12, 2015 8:12 am

Tom_A wrote:
LightningPi wrote:
Tom_A wrote: I wrote a guide on how to set this up here:
http://www.technicallytom.com/2013/12/1 ... pi-webcam/
What do I put for the "System Mail Name"?
I think I used the domain name my website uses, however I think this may not be as important as it looks. I think this sets the addresses on mail that is sent out, however if you follow the whole guide, the address will show up as from the gmail account you are using.
If I am not completely mistaken, the gmail stmp server will not allow you to send email with any other "from address" than the one of the account unless you specifically activate such a functionality on the account. IIRC when you do this you need to enter the authentification data needed to that other address into google's own settings page. I believe that this and the other issue here in this thread about having to allow less secure apps are both related to google wanting to make spamming significantly more difficult to do.

Tom_A
Posts: 272
Joined: Fri Dec 06, 2013 8:34 am

Re: Send an email when a file is created

Mon Jul 13, 2015 2:29 am

I just checked and the messages appear as coming from my gmail account. I think this may not have always been the case. I don't care what the from address reads as. I know where the messages are coming from. I still think that it doesn't matter what you put in the system mail name. I think it gets overridden when the mail gets set and that's why it doesn't matter.

User avatar
LightningPi
Posts: 24
Joined: Wed Mar 26, 2014 3:00 am

Re: Send an email when a file is created

Tue Jul 14, 2015 1:13 am

I finally found the problem. I was editing the example file the whole time!!! I have yet to test the correct one and will tell you when it works!
- LightningPi(a.k.a LightningJimmy)

User avatar
LightningPi
Posts: 24
Joined: Wed Mar 26, 2014 3:00 am

Re: Send an email when a file is created

Tue Jul 14, 2015 1:18 am

OMG!!!!!!!! It actually worked!!!! It worked!!!! I was an idiot!!! But it worked!!!!

Sorry for getting excited.... BUT I FINALLY MADE IT WORK!!!!
- LightningPi(a.k.a LightningJimmy)

Tom_A
Posts: 272
Joined: Fri Dec 06, 2013 8:34 am

Re: Send an email when a file is created

Tue Jul 14, 2015 4:25 pm

LightningPi wrote:OMG!!!!!!!! It actually worked!!!! It worked!!!! I was an idiot!!! But it worked!!!!

Sorry for getting excited.... BUT I FINALLY MADE IT WORK!!!!
Congratulations. Now that it's working, you'll be able to use it for other things as well if you want. I get notifications when new updates are available. You can also use fail2ban to prevent brute force login attempts for ssh or for a web server, for example. This is assuming that you have services exposed to the internet.

Return to “General discussion”