Robert Glavaš
Robert Glavaš

Reputation: 67

Shell Bash Script not work

i have bash script for backup my database and i use it on other server and work fine...

Script is:

#!/bin/bash

HOME="/var/www/html"
DB="$HOME/backup/vpn-db-`date +%Y-%m-%d-%H%M%S`.sql.gz"
LOG="$HOME/backup/log.txt"

echo "Backup database `date +%F` u `date +%H:%M:%S`."
echo "Backup database `date +%F` u `date +%H:%M:%S`." >> $LOG

mysqldump -u root -pmypassword mydatabase > $DB

echo "Finish at `date +%H:%M:%S`."
echo "Finish at `date +%H:%M:%S`." >> $LOG

Error was i get when try run from terminal is:

root@vpn:~# sudo bash /var/www/html/backup/cron.sh

/var/www/html/backup/cron.sh: line 2: $'\r': command not found
/var/www/html/backup/cron.sh: line 6: $'\r': command not found
Backup database 2017-04-04 u 13:51:10.
: No such file or directory: /var/www/html
/var/www/html/backup/cron.sh: line 9: $'\r': command not found
: No such file or directory gz /var/www/html
/var/www/html/backup/cron.sh: line 11: $'\r': command not found
Finish at 13:51:10.
: No such file or directory 3: /var/www/html
/var/www/html/backup/cron.sh: line 14: $'\r': command not found

NOTE - Permissions of file is: 774

Upvotes: 1

Views: 74

Answers (1)

Stefan Hegny
Stefan Hegny

Reputation: 2187

You've probably edited the file on windoze or transferred it via windoze where one of the transfers was binary and the other text mode, thus it has trailing Carriage Returns.

Try dos2unix /var/www/html/backup/cron.sh to make the CRs go away.

Upvotes: 2

Related Questions