linuxbashshellneoscms

Empty Bash line throws error


I wrote a small NEOS backups script that dumps my mysql database and compress this..

On my Laptop (Deepin OS) the script runs well but on the server it throw errors...

https://gist.github.com/breadlesscode/2f2e274a3c9314b99ac71fc6b2afb07a

Empty Lines throw errors?! I dont know why. I have tried diffrent lineendings, but it doesent work.

bash -x ./crons/BackupNeos.sh Output:

+ 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.

Anyone can help me?


Solution

  • '\r' is Windows EOL marker which don't work weel in unix-like OSes.

    try

    dos2unix ./crons/BackupNeos.sh
    

    Which will convert EOL to correct one.

    Alternative approach using sed:

    sed -i 's/^M$//' ./crons/BackupNeos.sh