-2

The following cron job fails to execute. What's wrong with it? It works fine when I run it directly from the shell prompt.

www-data@etl:~$ crontab -l
SHELL=/bin/bash
MAITO=""

0 5 * * *   export YESTERDAY=$(date --date "yesterday" "+%Y-%m-%d"); cd /var/www/project && source .env/bin/activate && ./manage.py get_orders --date="$YESTERDAY" && sleep 5m && time ./manage.py merch --date="$YESTERDAY" && time ./manage.py order_flat_report --date="$YESTERDAY" && time ./manage.py update_hourly_report --date="$YESTERDAY"

I'm getting this error message:

Return-Path: <www-data@etl>
X-Original-To: www-data
Delivered-To: www-data@etl
Received: by localhost (Postfix, from userid 33)
    id E170C43EC7; Fri, 18 Apr 2014 05:00:01 -0400 (EDT)
From: root@etl (Cron Daemon)
To: www-data@etl
Subject: Cron <www-data@etl> export YESTERDAY=$(date --date "yesterday" "+
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/bash>
X-Cron-Env: <MAITO=>
X-Cron-Env: <HOME=/var/www>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=www-data>
Message-Id: <20140418090001.E170C43EC7@localhost>
Date: Fri, 18 Apr 2014 05:00:01 -0400 (EDT)

/bin/bash: -c: line 0: unexpected EOF while looking for matching `"'
/bin/bash: -c: line 1: syntax error: unexpected end of file
  • Ubuntu 13.10 (GNU/Linux 3.11.0-14-generic x86_64)
  • GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)
2
  • 3
    I suggest you put it in a bash script file and execute it. Apr 18, 2014 at 12:26
  • 1
    Work your way through the duplicate above, doing so will solve your problem.
    – user9517
    Apr 18, 2014 at 14:14

1 Answer 1

1

It looks like cron does not correctly escape some of the quotes in your command while it passes the command to bash. As Florin suggests, you could put the command into a shell script, make it executable, store it e.g. in /usr/local/bin, and run it as a cronjob.

If it is not important that the job is run exactly at 05:00, you can also put the script in /etc/cron.daily/, thus avoiding the need to call it from crontab.

Not the answer you're looking for? Browse other questions tagged .