SH issues

Hi all,

I have a backup script which runs daily and backups up MySQL databases. I’ve just checked it out and found that it hasn’t worked for about 3 or so months. I haven’t changed anything on my script and get weird errors if I run the script from SSH. I’ve had to change my script a little but still receive errors.

mkdir archives
suffix=$(date +%y%m%d)
mysqldump --opt -uforum -pxxxx -h forum > archives/forum.$(date +%y%m%d).sql
tar -cf /home/xxxx/backups/mysql_backup.$(date +%y%m%d).tar archives/*
rm -r archives

[boyd]$ sh
: No such file or directoryforum.090101.sql
tar: Removing leading `/’ from member names
tar: /home/xxxxx/backups/archives/*\r: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

It seems like it doesn’t even process the mkdir command or the rmdir command at all. If I create the archives directory then the tar command works but the script doesn’t delete the directory.

Also I used to have the below but it no longer works, instead it gives a filename name of forum.090101 and it’s missing the .sql part:
suffix=$(date +%y%m%d)
mysqldump --opt -uforum -pxxxx -h forum > archives/forum.$suffix.sql

Does anyone know if Dreamhost changed something?


Your script sets $suffix, but never uses it. I’d also put a ~/ in front of ‘archives’ so it’s always properly referenced.

It also looks like you edited the script in Windows, which is why there are some glitches like \r. Run ‘dos2unix’ to clean it up.


Hi Scott,

I’ve run dos2unix on it and it now appears to be working. Thank you!