我很抱歉再次提出这个问题,但我已经尝试了所有的build议。 我在/var/TPbackup_script/
有两个脚本。 这是第一个:
mysqldump -u root -pPASSWORD teampass > /var/TPbackups/TPbackup_$(date +"%Y-%m-%d").sql
/etc/crontab
相应的cronjob
20 9 * * * root sudo sh /var/TPbackup_script/TPbackup_script
这个脚本在crontab中有效。 一切都很好。 第二个脚本不运行:
s3cmd sync /var/TPbackups s3://PwdMgmt
/etc/crontab
对应的cronjob:
25 9 * * * root sudo sh /var/TPbackup_script/TPsyncS3_script
这一个失败。 如果我在terminal中手动运行它:
sudo sh /var/TPbackup_script/TPsyncS3_script
那么它完美的作品。 我试过了:
1)尝试将shebang#!/ bin / sh添加到脚本的开头
2)将脚本重命名为TPsyncS3_script.sh
3)我已经将脚本添加到cron.daily,它在每日cron任务列表(我看到它与命令run-parts --test /etc/cron.daily
)
没有成功。
这是我的/ etc / crontab文件:
# /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # mh dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 16 9 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) 20 9 * * * root sudo sh /var/TPbackup_script/TPbackup_script 25 9 * * * root sudo sh /var/TPbackup_script/TPsyncS3_script.sh > /var/TPbackup_script/sync_log.txt #
脚本的所有权限都使用sudo chmod 777
进行设置。
顺便说一下。 cronjob后创build了sync_log.txt,但是它是空的。
任何帮助表示赞赏
有同样的问题。 通过添加选项来指定s3cfg的位置来解决这个问题:
--config /root/.s3cfg
例如:
s3cmd sync --config /root/.s3cfg /var/TPbackups s3://PwdMgmt
我有一个类似的问题。 尝试使用root的crontab运行你的脚本。 做:sudo crontab -e
添加您的脚本,然后重试。 它为我工作:)