I have motion setup on a Raspberry Pi in rasbian-wheezy. Most of the motion.conf file works (I can view a live feed and it writes videos to the correct locations). However, I seem to be incapable of running anything from the on_motion_detected option.

Here's the original section:

#Command to be executed when a motion frame is detected (default: none)

; on_motion_detected value

and what I changed it too:

# Command to be executed when a motion frame is detected (default: none)

on_motion_detected /home/path/to/motionscr

motionscr is a script I wrote which works fine in a terminal using the exact same command. I also ran chmod +x /home/path/to/motionscr I can't find any documentation on the proper syntax for this option if I'm somehow writing it wrong.

I have already read this question and this article


I have a script named upload_picture in one of my folders and I invoke this when a picture is ready to be saved. My etc/motion/motion.conf file has a line almost identical to yours. Mine reads:

on_picture_save /home/derek/webcam/upload_picture

my upload_picture script is quite simple. It sleeps 10 then uses wput to FTP the image to a web-site

I don't have an on_motion_detected setting, but looking here It seems the format is the same for the two options. So I'd check that your script is actually being called. And I'd do that by including an echo "Running" > /tmp/foo line to the script. Also make sure whatever account is running motion has access to run the script, and probably that it has a shebang at the top (#!/bin/sh). When you change motion/conf you would probably want to restart motion and the link I copied explains that.

Another thing you could try is at the end of the on_motion_detected line put >/tmp/motion.log 2>&1 which will record output from your script to a log file

| improve this answer | |

This configuration works for me:

on_motion_detected /usr/bin/python /home/myuser/Scripts/MyScript.py

Of course, the script must have the correct permissions to be executed by the motion process. More details on the configuration can be found here: http://www.lavrsen.dk/foswiki/bin/view/Motion/ConfigFileOptions

| improve this answer | |

This syntax worked for me, here is an extract of my /etc/motion/motion.config file

# 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

 on_movie_end `/pass/to/your script.sh`

## Command to be executed when a camera can't be opened or if it is lost
# NOTE: There is situations when motion don't detect a lost camera!
| improve this answer | |

It seems this answer is not yet answered.

I have had the same issue and I suspect it could be because motion runs as the user motion and therefore does not have the necessary rights as the fileowner would.

Try sudo -u /home/path/to/motionscr

| improve this answer | |

Hahaha... I just found the solution. Whenever an error makes no sense, then you know you've looked over something in plain sight.

Look at your command closely:

#Command to be executed when a motion frame is detected (default: none)
; on_motion_detected value

See the ';' at the 2nd line? The line is commented out...

| improve this answer | |
  • 1
    The OP has removed the ;, in the second example, where they have entered the path to their script. – Greenonline Oct 13 '18 at 20:39

Try the following:

on_picture_save sh /home/path/to/motionscr.sh

Double check that:

  • The 'motion' user is able to execute the 'motionscr.sh' script

    sudo chown motion:motion /home/path/to/motionscr.sh

  • Whatever the script does, make sure all of their commands have the right privileges (user & location wise).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy