我很抱歉再次提出这个问题,但我已经尝试了所有的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:
Bash脚本不能在Cron中正确执行
Cron作业不运行
Cron API:有这样的事吗?
脚本中的bash for-loop不能以非root用户的cron脚本运行
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,但是它是空的。
任何帮助表示赞赏
限制cron在linux / shell中发送邮件5分钟
安排cron作业打开terminal并按顺序运行命令
rdiff备份bash脚本和cron的麻烦
添加10分钟的cron作业到Ubuntu包
使用crontab -lsearchcronjob
有同样的问题。 通过添加选项来指定s3cfg的位置来解决这个问题:
--config /root/.s3cfg
例如:
s3cmd sync --config /root/.s3cfg /var/TPbackups s3://PwdMgmt
我有一个类似的问题。 尝试使用root的crontab运行你的脚本。 做:sudo crontab -e
添加您的脚本,然后重试。 它为我工作:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。