1

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

1
  • @VIPINKUMAR drwxr-xr-x 5 root root 4096 Tra 4 11:02 /var/www/html/ Commented Apr 4, 2017 at 12:01

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.