Am 20.06.2011 00:37, schrieb Grant:
> One of my systems has a crontab like this to clean up and consolidate
> the output of the video monitoring app "motion":
> 
> # crontab -l
> # DO NOT EDIT THIS FILE - edit the master and reinstall.
> # (/home/grant/cron.root.txt installed on Sat Sep 25 10:42:18 2010)
> # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
> 50 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.jpg
> 55 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.avi
> 59 23 * * * /usr/bin/mencoder /home/motion/$(date +%Y%m%d)*.avi -noidx
> -o /home/motion/full-$(date +%Y%m%d).avi -ovc copy -oac copy
> 
> If I execute each command manually, it works great, but nothing
> happens otherwise.  Can someone tell me why this crontab doesn't seem
> to be executing?
> 
> - Grant
> 

I might be wrong but as I understand it, cron executes your commands in
/bin/sh, not /bin/bash. Therefore you should use the `date -d
'yesterday' +%Y%m%d` syntax instead of $(date -d 'yesterday' +%Y%m%d).

Additionally, % signs are replaced with newlines. You have to escape
them: `date -d 'yesterday' +\%Y\%m\%d`

Hope this helps,
Florian Philipp

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to