This question already has an answer here:

I am trying to add a cron job to perform an rsync from a remote server to a (Ubuntu12) local machine & create a log file.

Below is the crontab-l

00 18 * * * rsync -a -v --delete -e ssh user@centosvm:/home/user/rsync-test ~/backup > ~/rsync$(date +%Y%m%d_%H%M%S).log 2>&1

i kept getting this mail informing about the syntax error in the job.

Received: by work-virtual-machine (Postfix, from userid 1002)

        id 697ADA24A0; Thu, 30 Apr 2015 16:21:01 -0700 (PDT)

From: root@work-virtual-machine (Cron Daemon)

To: user@work-virtual-machine

Subject: Cron <user@work-virtual-machine> "rsync -a -v --delete -e ssh user@centosvm:/home/user/rsync-test ~/backup > /home/user/rsync$(date +

Content-Type: text/plain; charset=ANSI_X3.4-1968

X-Cron-Env: <SHELL=/bin/sh>

X-Cron-Env: <HOME=/home/user>

X-Cron-Env: <PATH=/usr/bin:/bin>

X-Cron-Env: <LOGNAME=user>

Message-Id: <20150430232101.697ADA24A0@work-virtual-machine>

Date: Thu, 30 Apr 2015 16:21:01 -0700 (PDT)

/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")

i have also installed unix2dos package.

marked as duplicate by Gilles linux May 1 '15 at 20:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


okay - figured it out. Posting back just incase if someone runs into it someday at sometime. The % sign has a special meaning in crontab. it's changed to newline and any string after the first % will be sent to the command as standard input. To force cron to interpret it literally, you have to escape it:

00 18 * * * rsync -a -v --delete -e ssh user@centosvm:/home/user/rsync-test ~/backup > ~/rsync$(date +\%Y\%m\%d_\%H\%M\%S).log 2>&1
  • Glad. That it helped – OK999 Mar 22 '17 at 17:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.