【发布时间】:2016-10-13 22:02:27
【问题描述】:
我有一个 cron 作业设置来运行 bash 脚本以每晚推送到 Git。
cron 作业设置为 root,我已通过:git config credential.helper store 设置了我的 git 凭据:Git push: username, password, how to avoid?(第二个答案)
bash 脚本的代码非常简单
#!/bin/bash
# Nightly push to Bitbucket
# Set some variables
DAY=$(date +%F);
# Make sure we run as root
if [ "$(whoami)" != "root" ]; then
echo "Only root can do this.";
exit 1;
else
# Make sure we are in the right directory
cd /hosting;
# Now add any changes
git add .;
# Now commit
git commit -m "$DAY Nightly";
git push all;
fi;
只要我登录到服务器并以 root 身份运行它,它就可以毫无问题地运行。
但是,它并没有在指定的时间运行。
Crontab -e 设置为:30 3 * * * back-to-git >/dev/null 2>&1
我该怎么做才能让它工作?
【问题讨论】:
-
什么是cronjob配置?在这里分享一下,看看那里有没有问题。另外,检查debugging crontab。
-
更新了问题以包含该工作,我稍后会查看该链接
-
这可能是你如何调用你的脚本的问题:
back-to-git单独是 cron 找不到的东西。它是您主目录中的脚本吗?然后确保编写完整路径以及执行它的二进制文件 -->/bin/bash /home/your_user/back-to-git -
这是
/usr/bin中的脚本也有执行权限 -
尝试在脚本开头添加
(date; whoami) > /tmp/cron-log.txt之类的内容,并在脚本失败后检查/tmp/cron-log.txt的内容。如果文件在那里,则作业确实触发了。如果没有,你有一个 cron 问题(不是 Git 问题)。