1

If this site gives this as an example of controlling Motion via cron as:

0 9 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/start > /dev/null

1) is this the correct sintax to work from the command line?

sudo /usr/bin/wget http://localhost:8091/0/config/set?threshold=1000&username=myuserename&password=mypassword> /dev/null

2) can someone please explain exactly what this line is doing.

3) my motion.conf file is located in /etc with permission 0755, does this mean user "motion" will not be able to write to the file?

2

1) Close. I think the intention of the cron line though is that the file doesn't get saved and output is suppressed, so I think it actually works out to this:

sudo /usr/bin/wget -O /dev/null -q http://localhost:8091/0/config/set?threshold=1000&username=myuserename&password=mypassword

2) OK. There's things happening here on two levels. The system level and the motion level. I'll start with the former. The sudo command is making it so that the wget application is running as root. wget is a tool to fetch web-pages from the command line. The -O /dev/null means that rather than saving the file it's sent to /dev/null, which means that effectively all that's happening is a GET request is happening. It's equivalent to going to that link in your browser, but then ignoring what shows up in the browser window. The -q just means we don't hear anything about what's happening in the console. The > /dev/null in the cron line is the equivalent to both the -O and -q parameters in wget.

What's happening at the motion level is that motion runs a webserver on port 8091 which works just like a regular web page to allow controlling the software remotely. This particular link to the changes the threshold for detecting motion to 10000, which makes it relatively insensitive compared to the default value of 1500. It uses the username username and the password mypassword for access to the server to verify it's actually you sending it the change threshold command.

3) It depends on who owns the /etc/motion.conf file. If the user 'motion' that runs motion also owns it then it will be able to write. If it doesn't then it won't. The easy way around this is to run chmod 777 /etc/motion.conf which makes it so that everyone under the sun can read and write to the file. You can use ls -l /etc/motion.conf to find out who owns the file. You can change the ownership of the file by running chown motion /etc/motion.conf instead of using chmod to make sure it writable by the user motion only. root will still be able to write to it too because root ignores these permissions.

  • Thanks Fred for your reply, i tried your command line modifications, and it appeared to work, but when i go to /etc/motion.conf, there is no change. Iv'e made motion.conf chmod 777, but still no change. I'm sure i'm doing something fundamentally wrong. Whatever i do i cannot see changes via the web interface, migrate to the motion.conf file. It looks like your command line trick worked; it also looks like it's working from motions web browser control interface; but i cannot seem to modify the motion.conf file in any other way than manually! any ideas? – reggie Mar 15 '14 at 12:40
  • I think you need to manually trigger a configuration write to save the changes you've made, otherwise they only in memory and are reset the next time motion starts. Something like wget -O /dev/null -q http://localhost:8091/0/config/writeyes?username=myuserename&password=mypassword I think. – Fred Mar 15 '14 at 12:44
  • ok, i did via terminal 'sudo /usr/bin/wget -O /dev/null -q localhost:8091/0/config/…' which gave [1] 23890 [2] 23891; followed by 'sudo /usr/bin/ wget -O /dev/null -q localhost:8091/0/config/…' which gave [3] 23895 [1] Exit 6 sudo /usr/bin/wget -O /dev/null -q localhost:8091/0/config /set?threshold=3500 [2] Done username=myusername But still no change in the motion.conf file. – reggie Mar 15 '14 at 13:06
  • should i be able to see the changes in the motion.conf file? I think i'm doing something fundamentally wrong. Are there ant tests/logs/debug things i can look at, to try and give me an idea of what i'm doing wrong? – reggie Mar 15 '14 at 13:38
  • 1
    Unfortunately I'm not much of a motion expert so we're reaching the end of what I know. There might be error reporting in /var/log/messages. – Fred Mar 15 '14 at 18:55
1

I gave up on trying to control motion the way your're suppose to, so decided to write my own rough and ready python script.

It essentially searches through the motion.conf for predefined strings "from strings", then replaces them with "to strings". I call the python scrip using a cronjob to automate the process.

Below is the script, if anyone is having the same problems as I did for ages!

#!/usr/bin/env python

###############################################################################
# This script opens Motion's configuration file, searches through it for  
# "from" then copies the contents and replacements "to" 
# (eg from = threshold 300 to threshold 6000) to the tmp.conf file.
# It then renames the un-modified existing motion.conf file to 
# "motion_old.conf" for backup purposes; before renaming the "temp.conf" to 
# "motion.conf", the new modified file.
# It then sets the new motion.conf file to user "motion" and group "motion", 
# before restarting motion.
###############################################################################

###############################################################################
# call the script from cronjob for 5:30AM
#
# 30 5 * * * sudo /usr/src/scripts/mod_file/modify_motionconf_night_to_day_garden.py
#
###############################################################################

import os, sys

infile = open('/etc/motion.conf')           # the motion.conf file that will be renamed for backup purposes
outfile = open('/etc/tmp.conf', 'w')        # temp file to write to

#                from            to
replacements = {'threshold 300':'threshold 6000', 'text_left garden cam night':'text_left garden cam day', '#----night----#':'#----day----#'} 
#                threshold 189                     text_left 389                                            #----xxx----# 5   line numbers in motion.conf

############################################################################### search and create new temp file part
for line in infile:                                 
    for src, target in replacements.items(): 
        line = line.replace(src, target)        
    outfile.write(line)
infile.close()
outfile.close()
############################################################################### search and create new temp file part end

#os.remove('/etc/motion.conf') # uncomment if you don't want a backup
os.rename("/etc/motion.conf","/etc/motion_old.conf")
#delay or not?
os.rename("/etc/tmp.conf","/etc/motion.conf")
os.system("chown :motion /etc/motion.conf")
os.system("chown motion /etc/motion.conf")

os.system("sudo /etc/init.d/motion restart")

It's not elegant, but it works,

Kind Regards,

Reggie.

1

I was intending something similar using wget and didn't work..

since i quit the -q operand and i can see that the connection was done but rejected because of the authentication,

then i search on the manual with

man wget

there i found:

    --user=user
    --password=password
       Specify the username user and password password for both FTP and HTTP file retrieval. 

According with this i think your syntax should be:

sudo /usr/bin/wget -O /dev/null --user=myuserename --password=mypassword http://localhost:8091/0/config/set?threshold=1000

it works for me,

like i said, i was intending something similar, in my case i was intending to start and pause the motion detection via CRON, then my exact code was:

0 8 * * 1-5 sudo /usr/bin/wget -O /dev/null --user=myuser --password=mypassword http://localhost:80/0/detection/pause

and

0 18 * * 1-5 sudo /usr/bin/wget -O /dev/null --user=myuser --password=mypassword http://localhost:80/0/detection/start

SALUT !!!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.