SH issues


#1

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.

#!/bin/bash
mkdir archives
suffix=$(date +%y%m%d)
mysqldump --opt -uforum -pxxxx -h mysql.xxxx.net 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 mysql.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 mysql.xxxx.net forum > archives/forum.$suffix.sql

Does anyone know if Dreamhost changed something?

Thanks,
Alex.


#2

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 mysql.sh’ to clean it up.

-Scott


#3

Hi Scott,

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