I have the following bash script for daily backing up of mysql database and deleting some temporary files. Its main steps are: (1) Use mysqldump to create a backup .sql file; (2) Zip up the file; (3) Copy the file to a Windows shared folder using smbclient; (4) Delete the sql and zip file created; (5) Delete some files from a directory.
#!/usr/bin/env bash
Date=`date "+%Y%m%d%H%M%S%n"`
DBUser="mydbuser"
UserPassword="mydbpassword"
BkpUser="mybkpuser"
BkpPassword="mybkppassword"
mysqldump mydatabase -u$DBUser -p$UserPassword > /home/me/daily-backup/mydatabase.sql
cd /home/me/daily-backup/
zip mydatabase-"$Date".zip mydatabase.sql
smbclient "//bkpserver/backup" -I10.10.1.10 -Wworkgroup -U $BkpUser%$BkpPassword < /home/me/scripts/smbclient-commands
rm mydatabase.sql mydatabase-"$Date".zip
cd /home/me/tempfiles/
rm -f *.csv
The file smbclient-commands has the following contents
prompt
mput *.zip
quit
I set up cron with the following
crontab -u me -e
and then input the following line
00 05 * * * /home/me/scripts/dailybackup.sh
cron runs successfully, but instead of executing the shell script properly, it creates a binary file in /home/me/daily-backup/. When I run the script manually, it works perfectly. I have given execute permissions on script to user and other, read is allowed for user, group, and other. daily-backup directory has read, write, and execute permission for user and other. smbclient-commands file has read permission for user, group, and other; write permission to user.
I am using Ubuntu Gutsy server edition. Is there something I am doing wrong and need to correct so that it runs properly?
Bookmarks