I would like to run the bash script in CentOS 7 in terminal to export database dump. However, it ends with error.
backup_test.sh
#!/bin/bash
thisthing=fiveminute
dumpfile=db-${thisthing}-`date +%Y%m%d%H%M`.sql
mysqldump database_name > $dumpfile.tmp
mv $dumpfile.tmp $dumpfile
I have setup my ~/.my.cnf to be able to run dump without asking for user password:
.my.cnf
[mysqldump]
user=username
password=password
skip-extended-insert
skip-dump-date
Execution from terminal
[site.backup@localhost ~]$ ./backup_test.sh
This ends up in following error:
-bash: ./backup_test.sh: /bin/bash^M: bad interpreter: No such file or directory
Can anyone please guide where I am going wrong??
Edit #1
Permissions are set properly as backup_test.sh is set to be executable
Solution
The problem was due to the Windows based line endings, \r, guess I copied the script from Windows based file into the Centos file, hence the error.
To change the script from Windows encoding to Unix in vim
you could also use :set ff=unix
and then save the file, or :set ff=dos
to get DOS formatting again.