Shelldbbackup. sh: {code...} crontab {code. Shell
Dbbackup. sh:
mysqldump -uname -ppassword dbname | gzip > /www/web/mysqlbackup/xiangyanghua`date +%Y-%m-%d_%H%M%S`.sql.gz
Crontab
37 22 * * * root /www/web/mysqlbackup/dbbackup.sh
Where is the problem.
Reply content:
Shell
Dbbackup. sh:
mysqldump -uname -ppassword dbname | gzip > /www/web/mysqlbackup/xiangyanghua`date +%Y-%m-%d_%H%M%S`.sql.gz
Crontab
37 22 * * * root /www/web/mysqlbackup/dbbackup.sh
Where is the problem.
1. run the command directly.
2. is the crontab service enabled?
1 The crontab task will be executed as the current user. it is useless to add the root user;
2. run the command manually to check whether the command is successful or whether there are other errors;
3. add the log content to the file in your dbbackup. sh script, for example, add the log content to the start line and end line.
echo $(date)--start >> /tmp/xxx.log
This method is used to determine whether the script is executed and where an error occurs;
4. add standard output and error output to the crontab task.
37 22 * * * /www/web/mysqlbackup/dbbackup.sh > /tmp/dbback.log 2>&1
5. executable permissions of the script
6. if mysqldump is installed in source code, you need to pay attention to the path environment variable problem. crontab may not be able to read the path, so in the script, mysqldump should write the absolute path;