cron: missing double quote

Hi all,

This single-line command works fine on the command-line:
Code:
$ spamdb | grep WHITE > /home/colin/log/whitelist-$(date "+%Y%m%d").txt && cat /home/colin/log/whitelist-$(date "+%Y%m%d").txt| awk -F "|" '{print $2}' | xargs -I{} spamdb -a '{}'

However, as a cron job, it generates an error message every time it is invoked:
Code:
/usr/local/bin/bash: -c: line 0: unexpected EOF while looking for matching `"'
/usr/local/bin/bash: -c: line 1: syntax error: unexpected end of file
Anyone have any ideas why?
 
Erm, why is cron(8) using bash(1)?

In any case, since this is a rather complex one-liner why not spread it out in a proper script and call that?
 
Erm, why is cron(8) using bash(1)?
Code:
#FreeBSD: src/etc/crontab,v 1.32 2002/11/22 16:13:39 tom Exp $
#
SHELL=/usr/local/bin/bash
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
[...]
Not a good idea?
 
No, definitely not a good idea. And it's also not a good idea to edit /etc/crontab.

Use crontab -e.
 
I do edit my crontab this way. I was just trying to indicate why cron is using bash in my situation; because I added that line at the top. I can't remember now exactly why; I think I was using something bash-only somewhere.

Anyway, I took your advice and made a script of the line above.
 
As soon as you start using complex commands and redirects, it's almost always better to put these things in a script (a bash script if you must), and execute that script from cron.
 
Keep the normal shell for cron(8).

Scripts all have a hash-bang, so if any need bash it'll use bash.

Code:
#!/usr/local/bin/bash
 
Back
Top