Linux Ubuntu automatically backs up the mysql script on a regular basis, and there is no problem with the content in the script.

I wrote a sh script on linux. When I used the command to execute the script, the execution was successful. A normal sql file is generated in the path I wrote.
mysql account password is in the configuration file.
script content:


-sharp!/bin/bash/
mysqldump -u root jeeplus_jinqiu > /data/backup/jeeplus_jinqiu_$(date +%Y%m%d_%H%M%S).sql

then I do
crontab to execute my script at 12:00 every night. It did. But the executed sql script is 0k and has no content.

I wondered if it might be a root mysql permission problem. But I don"t think so. My crontab is also done under the authority of root.

excuse me, what kind of problem will it be? How to solve it

Mar.09,2021

commands and files all use absolute paths to try


to check the problem of chemical variables, you can add:

to the calling script
  • source / etc/bash_profile

may be a problem of environment variables, it is best to use absolute path


cron log. It should be a problem of environmental variables. Execution is not successful. You can use the absolute path


  1. for the problem of environment variables, you can source
  2. first.
  3. Command is exercised with absolute path

mysqldump is changed to the absolute path of mysqldump, such as / usr/bin/mysqldump


just look at the script, shebang is wrong, with an extra tail / ; it should be -sharp! / bin/bash

either google crontab error log or rtfm, can directly locate the problem.

If standard output and standard error are not redirected by commands executed from the crontab entry, any generated output or errors shall be mailed, via an implementation-defined method, to the user.
man crontab
Menu