#51: Broken shell command substitution in crontab

Solved!
In a cronjob, I want to execute a date sub-command and substitute the results in place into the overall shell command. Something like:

1 5 * * * bash -c 'cp /foo/bar /foo/bar.$(date +%Y%m%d).sql'

Unfortunately, this breaks with an error at runtime:
/bin/bash: -c: line 0: unexpected EOF while looking for matching `'' /bin/bash: -c: line 1: syntax error: unexpected end of file

I am obviously missing something here.

Escape percent signs in crontabs

4
Percent signs must be escaped in crontab, as % has special meaning in crontabs. Use backslash to escape.

Think you've got a better solution? Help 92049143cabb7ba896d7c06e19906303_small yliu out by posting your solution

Re: command substitution in a crontab with SHELL=/bin/bash

http://lists.debian.org/debian-user/2001/02/msg03838.html# - found by 92049143cabb7ba896d7c06e19906303_small yliu on June 04, 2009, 11:14 AM UTC

same deal.

Tags: shell crontab cronjob gotcha

crontab, command substitution and bash

http://www.mydatabasesupport.com/forums/shell/176999-crontab-command-substitution-bash.html# - found by 92049143cabb7ba896d7c06e19906303_small yliu on June 04, 2009, 11:14 AM UTC

sounds like the problem to me

Tags: cron shell cronjob bash command substitution gotcha UNIX