linux – Bash脚本的工作原理是提示,但不是来自cron

前端之家收集整理的这篇文章主要介绍了linux – Bash脚本的工作原理是提示,但不是来自cron前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
从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

如果你不逃避它们,它们将被视为换行符.

猜你在找的Linux相关文章