1 |
Am 20.06.2011 00:37, schrieb Grant: |
2 |
> One of my systems has a crontab like this to clean up and consolidate |
3 |
> the output of the video monitoring app "motion": |
4 |
> |
5 |
> # crontab -l |
6 |
> # DO NOT EDIT THIS FILE - edit the master and reinstall. |
7 |
> # (/home/grant/cron.root.txt installed on Sat Sep 25 10:42:18 2010) |
8 |
> # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $) |
9 |
> 50 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.jpg |
10 |
> 55 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.avi |
11 |
> 59 23 * * * /usr/bin/mencoder /home/motion/$(date +%Y%m%d)*.avi -noidx |
12 |
> -o /home/motion/full-$(date +%Y%m%d).avi -ovc copy -oac copy |
13 |
> |
14 |
> If I execute each command manually, it works great, but nothing |
15 |
> happens otherwise. Can someone tell me why this crontab doesn't seem |
16 |
> to be executing? |
17 |
> |
18 |
> - Grant |
19 |
> |
20 |
|
21 |
I might be wrong but as I understand it, cron executes your commands in |
22 |
/bin/sh, not /bin/bash. Therefore you should use the `date -d |
23 |
'yesterday' +%Y%m%d` syntax instead of $(date -d 'yesterday' +%Y%m%d). |
24 |
|
25 |
Additionally, % signs are replaced with newlines. You have to escape |
26 |
them: `date -d 'yesterday' +\%Y\%m\%d` |
27 |
|
28 |
Hope this helps, |
29 |
Florian Philipp |