Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When running a bash script from cron it fails with the following error

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file

The strange thing is it works perfectly when executed from the prompt

Whole Script

NOW=$(date +"%b-%d-%y")


echo ""
echo "Starting backup: $curtime"
echo ""
echo "Moving to $bu_PATH"
cd $bu_PATH


echo ""
echo "The backup file will be called $BACKUP_FILE"

RUN_BACKUP="/usr/local/psa/bin/pleskbackup --server --output-file=$bu_PATH$BACKUP_FILE"

echo "Running backup...."
echo `$RUN_BACKUP`


echo "Backup complete: $curtime"

echo ""

echo "Remove older than 7 days of files..."
ssh server '/shares/backup/webserver/'

echo ""

echo "Connecting to FTP: $curtime"

sftp -b server <<EOF
        cd /shares/backup/webserver/
        put $bu_PATH$BACKUP_FILE

echo "FTP Transfer Complete: $curtime"
echo ""
echo "Cleaning up Local backups"
sh /home/
echo ""
echo "Clean up log files"
find /home/webserver/logs/*.log -mtime +7 -exec rm {} \;
echo "Job Complete"

This is the crontab entry

/home/ > /home/webserver/logs/BackupLog-`date +%m%d%y`.log

Thanks Rob

share|improve this question
The error clearly states that no matching __ character was found. Is there somewhere in your script, are you executing something via backticks? – Janne Pikkarainen Aug 10 '11 at 10:20
Show is the crontab entry – Iain Aug 10 '11 at 10:26
as a note, you may be able to use tmpwatch here and there to make the script a bit smaller. – Sirex Aug 10 '11 at 14:16
up vote 8 down vote accepted

You need to escape the % signs in the crontab entry if you use backticks (`) in crontab.

like this:

/home/ > /home/webserver/logs/BackupLog-`date +\%m\%d\%y`.log

They are treated as newline if you dont escape them.

share|improve this answer
This fixed the crontab – Rob Aug 10 '11 at 10:47

Your EOF looks wrong, EOF; doesn't match your expected EOF (remove the semi-colon).

[hlinden@dolphin tmp]$ cat 
cat <<EOF
[hlinden@dolphin tmp]$ sh line 6: warning: here-document at line 3 delimited by end-of-file (wanted `EOF')
[hlinden@dolphin tmp]$ sed -i s/\;// 
[hlinden@dolphin tmp]$ sh
[hlinden@dolphin tmp]$
share|improve this answer
Thanks but I got the same error even without the ; – Rob Aug 10 '11 at 10:31
Can you post the whole script? – HampusLi Aug 10 '11 at 10:33
echo $RUN_BACKUP looks suspicious. If that has a backtick in the output you could get weird results, plus the output will be formatted badly. Why not just have a line with $RUN_BACKUP without the echo and backticks. – HampusLi Aug 10 '11 at 10:42
Thanks I removed the echo and the backticks – Rob Aug 10 '11 at 10:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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