# cron: missing double quote



## cbrace (Nov 7, 2012)

Hi all,

This single-line command works fine on the command-line: 
	
	



```
$ 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:

```
/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?


----------



## SirDice (Nov 7, 2012)

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?


----------



## cbrace (Nov 7, 2012)

> Erm, why is cron(8) using bash(1)?




```
#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?


----------



## SirDice (Nov 7, 2012)

No, definitely not a good idea. And it's also not a good idea to edit /etc/crontab.

Use *crontab -e*.


----------



## cbrace (Nov 7, 2012)

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.


----------



## DutchDaemon (Nov 7, 2012)

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.


----------



## SirDice (Nov 7, 2012)

Keep the normal shell for cron(8).

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


```
#!/usr/local/bin/bash
```


----------

