从cron运行bash脚本时,它失败并出现以下错误
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``' /bin/sh: -c: line 1: Syntax error: unexpected end of file
全剧本
#!/bin/sh NOW=$(date +"%b-%d-%y") bu_PATH="/home/webserver/" curtime=$(date) echo "" echo "Starting backup: $curtime" echo "" echo "Moving to $bu_PATH" cd $bu_PATH BACKUP_FILE="backup_$NOW.tgz" 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` curtime=$(date) echo "Backup complete: $curtime" echo "" echo "Remove older than 7 days of files..." ssh server '/shares/backup/webserver/cleanup.sh' curtime=$(date) echo "" echo "Connecting to FTP: $curtime" sftp -b server <<EOF cd /shares/backup/webserver/ put $bu_PATH$BACKUP_FILE quit EOF; curtime=$(date) echo "FTP Transfer Complete: $curtime" echo "" echo "Cleaning up Local backups" sh /home/cleanup.sh echo "" echo "Clean up log files" find /home/webserver/logs/*.log -mtime +7 -exec rm {} \; echo "Job Complete"
这是crontab条目
/home/backup.sh > /home/webserver/logs/BackupLog-`date +%m%d%y`.log
谢谢
抢
解决方法
如果在crontab中使用反引号(`),则需要转义crontab条目中的%符号.
像这样:
/home/backup.sh > /home/webserver/logs/BackupLog-`date +\%m\%d\%y`.log
如果你不逃避它们,它们将被视为换行符.