我写了一个小的NEOS备份脚本来转储我的mysql数据库并压缩它。
在我的笔记本电脑(Deepin OS)上,脚本运行良好,但在服务器上却抛出错误...
https://gist.github.com/breadlesscode/2f2e274a3c9314b99ac71fc6b2afb07a
空行会引发错误?我不知道为什么。我尝试过不同的行进,但是确实行得通。
bash -x ./crons/BackupNeos.sh输出:
+ BACKUP_FOLDER=%s_NEOS_Backup + NEOS_ROOT=$'/html/neos\r' + BACKUP_ROOT=$'/html/backups\r' + NEOS_PACKAGE=$'My.Package\r' + COMPRESS_BACKUP=$'true\r' + NEOS_FLOW_EXPORT=$'true\r' + MYSQL_FULL_BACKUP=$'true\r' + MYSQL_HOST=$'server\r' + MYSQL_USER=$'user\r' + MYSQL_PW=$'password\r' + MYSQL_DB=$'database\r' +++ date +%Y-%m-%d_%H-%M-%S ++ printf %s_NEOS_Backup 2017-01-15_18-53-30 + BACKUP_FOLDER=$'2017-01-15_18-53-30_NEOS_Backup\r' ++ printf %s/%s $'/html/backups\r' $'2017-01-15_18-53-30_NEOS_Backup\r' + BACKUP_FOLDER_PATH=$'/html/backups\r/2017-01-15_18-53-30_NEOS_Backup\r\r' + $'\r' : Command not found.le 18: ' printf 'Backup script start:\n\n Backup script start: + cd $'/html/backups\r\r' : File or directory not foundtml/backups ' printf 'Create backup folder... + mkdir $'2017-01-15_18-53-30_NEOS_Backup\r\r' ' printf 'done!\n done! + $'\r' : Command not found.le 24: ./crons/BackupNeos.sh: Zeile 51: Syntax Error: worong eol.
有人可以帮助我吗?
'\r'
是Windows EOL标记,在类似Unix的操作系统中无法正常工作。
尝试
dos2unix ./crons/BackupNeos.sh
它将转换为正确的EOL。
使用sed
以下替代方法:
sed -i 's/^M$//' ./crons/BackupNeos.sh