# Questions on motion (logging and rc style script)



## ilemur (Feb 12, 2012)

I'm trying to set up video surveillance. One of the ideas is to run a camera only during specific hours (when nobody is at home). Currently *I* have the following script for ffserver stream:


```
# cat webcam2ffserver.sh
#!/bin/sh
ffmpeg=/usr/local/bin/ffmpeg
env LD_PRELOAD=/usr/local/lib/libv4l/v4l1compat.so $ffmpeg -f video4linux -s 640x480 -r 5 -i /dev/video0 http://127.0.0.1:8090/webcam1.ffm
```

I understand how to make it start up at some time. But how to kill it in the end from cron?

And because of shutting down camera at some point - my whole console gets spammed with messages 

```
Feb 12 19:58:40 <user.err> xxx motion: [2] v4l_start: set input [8]
Feb 12 19:58:50 <user.err> xxx motion: [2] Retrying until successful connection with camera
```

Is there any way to keep the user.err intact and only forward messages from motion to a specific file? Currently had to disable the whole *.err.


----------



## fluca1978 (Feb 14, 2012)

ilemur said:
			
		

> I understand how to make it start up at some time. But how to kill it in the end from cron?



A few approaches come into my mind:
- use pkill `# pkill ffmpeg` 
- store a pid file somewhere and kill the process with such pid at the given time. Since you are already using a script to start ffmpeg setting the pid file of the does suffice
- sysutils/timelimit could help too








			
				ilemur said:
			
		

> Is there any way to keep the user.err intact and only forward messages from motion to a specific file? Currently had to disable the whole *.err.



I suspect motion is going to syslog with the selector _user_ so the only chance is to place a line like:

```
user.err   /var/log/motion.log
```

in the /etc/syslog.conf before the console one but I'm not sure if this is a good idea (don't know how many programs use this selector).


----------



## ilemur (Feb 16, 2012)

What about forwarding all the output for error channel to /dev/null? Just can't get it to work in rc.script
rc.d/motion

```
#!/bin/sh
#
# motion.sh for rc.d usage 2006 Angel Carpintero
#
# Add the following line in /etc/rc.conf to enable motion at startup
#
# motion_enable="YES"
#

# PROVIDE: motion
# REQUIRE: DAEMON
# KEYWORD: shutdown

. /etc/rc.subr

motion_enable="${motion_enable-NO}"

name="motion"
rcvar=`set_rcvar`

command="/usr/local/bin/${name}"
pidfile="/var/run/${name}.pid"
required_files="/usr/local/etc/${name}.conf"

load_rc_config $name
run_rc_command "$1"
```

Tried different combinations of 2>/dev/null with no luck. Any suggestions? (


----------

