Can't get on_movie_end to do anything
I have tried multiple ways and various methods to use the on_movie_end option, but to no avail. No matter what I try, nothing happens and motion doesn't give any error messages relating to it, so I just don't know what to do.
I would like motion to send an email with the avi file attached to my address. But nothing happens.
I initially used this command:
mutt -s "Motion filmed clip at `date "+%m/%d/%y %l:%M:%S %p"`" -a "%f" firstname.lastname@example.org < /home/server/motion.txt
But nothing happens after the movie is made.
If i run the same command from the command line, it works fine (but I have to replace "%f" with a real file name, something like /home/server/file.avi). Thus I am thinking I am using "%f" wrong somehow, but I don't know how. I have also tried putting this command in a .sh script and calling that with on_move_end but also nothign happens.
The movies are created fine in their default folder, but no email is ever sent. I even tried to completely remove the -a option, so it just sends an email, that also doens't work, so I am wondering that for some reason on_move_end is not working.
Syslog shows no errors, not does mutt or ssmtp which I use as my MTA so I am at a loss.
If anyone can tell me how I can fix this, or how they get motion to email them their movie files when they are created, that'd be great.
Sadly, as there are no logs files produced, I can't give you guys much info, so I am hoping that my on_movie_end command is all that is wrong.
Paste in your error messages, config settings, terminal window output etc in this text field.
| Motion version:
| ffmpeg version:
| ffmpeg, mysql, postgresql
| Server OS:
| Ubuntu 8.04
- 23 Mar 2009
Did you try to call a shell script instead of add all in motion.conf ?
on_movie_end /tmp/mail.sh %f
uuencode $1 Video.avi | mail my_destination_email@my_mailserver.com
This works in stable ( 3.2.11 ) and also in trunk ...but it should in 3.2.9 too.
- 24 Mar 2009
Not sure quite how to reply to an answer here, hope I am doing it right.
I tried it both ways, with a direct command and a shell script, I guess I am not understanding how the on_movie_end passes the file name to the script using %f.
In your example you put %f after the script to pass the video name to the script, but then in your script example, I am not sure how the script gets the full video file name to process it. Is "$1 Video.avi" what I need to use? So in my example I should do the following:
mutt -s "Motion filmed clip at `date "+%m/%d/%y %l:%M:%S %p"`" -a "$1 Video.avi" email@example.com < /home/server/motion.txt
So "$1 Video.avi" is actually replaced with the full path to the file name, which is something like /home/server/motion/3-01200903251123.avi? This is where my confusion lies and where I guess I am having problems with. If you wouldn't mind explaining a little more about how %f and "$1 Video.avi" works I might be able to figure it all out. I'll also try and download and install from source so I am using the most recent version.
Thanks for your reply so far on this.
- First, read the answer of this question : http://www.lavrsen.dk/foswiki/bin/view/Motion/SupportQuestion2008x10x21x165451 and discover how it works "on_movie_end" feature.
- In fact we deal with 2 files : [motion.conf] and [create_video_link.sh]
- Let's translate in short : when "on_movie_end" happens, the motion program access script create_video_link.sh and this script create the file lastmotion.flv (in my example)
- Finally, with cron jobs you can do what you want with your lastmotion.xxx file : to send to an mail address, to upload to a ftp server, and so on...
- In my case I use this scenario : when motion is detected, this motion is saved in jpg and avi files (lastmotion.jpg and lastmotion.avi), then "on_picture_save" send to ftp server that jpg file, and finally a cron job (from 29 to 29 minutes) send the file lastmotion.flv to ftp server... (I convert lastmotion.avi to lastmotion.flv in [create_video_link.sh]) . If you are confused , please reply to share with you my [motion.conf]
- 24 Mar 2009
Thanks loads for your answer, it has helped me move forward. I still don't fully understand how the %f is used, but I can now use the on_movie_end correctly to do what I want, well almost.
No matter what I do, I get an error with ssmtp and the mail server I am using, it seems that when my mail command is called via motion, for whatever reason, despite setting the correct from address in teh config file, it uses an incorrect from address and the mail server rejects the mail before it is sent. I am sure this is down to the group that motion is running under, but I don't know enough about linux yet to work out how to fix that.
So, instead, I have created a modified version of Florin's script, to create a "lastmoviecamX.avi" file for my three webcams in a certain directory. I have then written another script that checks the files in this folder using diff -qs to see if the files are updated or not, if they are, it emails me the lasmoviecamx.avi file. All this is run by cron.
I would have preffered to have done all this from a script called by on_movie_end, but I could never get around the problem of this From address issue.
Well, thanks loads for the help.
- A redesign of the external commands was due. They were not very easy to understand, not all were flexible enough and some were missing. So a new external command feature set was made for 3.2.1 and on.
- Mail and sms has been removed because they were not configurable. If you want to send event-based mails or sms, just use one of those commands above (on_event_start/on_event_end/on_picture_save/on_movie_start/on_movie_end/on_motion_detected) and send the mail from that script.
- Maybe this can help you : http://www.lavrsen.dk/foswiki/bin/view/Motion/ExternalCommands#MailSMS
- 25 Mar 2009
Answer (Possible Root Cause)
I was attempting to use mutt and encountered the same problem. I am pretty sure this is due to mutt command being executed by user "motion". On my my system mutt will not operate in this way (mail dir for user does not exist as well as other things probably). I switched to uuencode method piped into mail as suggested in the Answer and things worked as expected.