鍍金池/ 問(wèn)答/Linux  數(shù)據(jù)庫(kù)/ Linux Ubuntu 定時(shí)自動(dòng)備份mysql腳本,腳本里沒(méi)內(nèi)容問(wèn)題。

Linux Ubuntu 定時(shí)自動(dòng)備份mysql腳本,腳本里沒(méi)內(nèi)容問(wèn)題。

我在linux上寫(xiě)了一個(gè)sh腳本。當(dāng)我用命令去執(zhí)行腳本的時(shí)候,執(zhí)行成功了。在我寫(xiě)的路徑里生成了一個(gè)正常的sql文件。
mysql 賬號(hào)密碼在配置文件當(dāng)中。
腳本內(nèi)容:


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

然后我做了
crontab 每晚12點(diǎn)執(zhí)行我這個(gè)腳本。確實(shí)執(zhí)行了。但是執(zhí)行出來(lái)的sql腳本是0k,沒(méi)有內(nèi)容。

我想過(guò)會(huì)不會(huì)是root mysql權(quán)限問(wèn)題。但是覺(jué)得不應(yīng)該。我crontab也是在root權(quán)限下做的。

請(qǐng)問(wèn)會(huì)是什么問(wèn)題照成的呢。怎么解決呢

回答
編輯回答
嫑吢丕
  1. 環(huán)境變量問(wèn)題,可以先source一下
  2. 命令行使用絕對(duì)路徑
2017年1月3日 15:27
編輯回答
青黛色

cron日志看下。。。應(yīng)該是環(huán)境變量問(wèn)題。執(zhí)行不成功,可以使用絕對(duì)路徑

2017年7月12日 16:36
編輯回答
抱緊我

mysqldump 改成 mysqldump的絕對(duì)路徑,比如 /usr/bin/mysqldump

2018年8月11日 03:57
編輯回答
萢萢糖

單純看腳本,是 shebang 錯(cuò)了,多了個(gè)尾巴 /; 應(yīng)該是 #!/bin/bash

google crontab error log 或者 rtfm,都能直接找到定位到問(wèn)題。

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
2018年4月19日 13:17
編輯回答
久愛(ài)她

命令、文件都使用絕對(duì)路徑試一下

2018年7月7日 16:32
編輯回答
胭脂淚

檢查一下化境變量的問(wèn)題,可以在叫腳本中加入:

  • source /etc/bash_profile

是有可能是環(huán)境變量的問(wèn)題的,最好使用絕對(duì)路徑

2017年6月20日 14:16