我正在运行 Ubuntu 10.04(64 位)并在 /etc/cron.hourly 中有以下脚本
cd /home/chris/path/to/directory
git add .
git commit -m "Commit message"
git push origin master
Run Code Online (Sandbox Code Playgroud)
该文件是 775,我可以手动运行它运行脚本并查看它推送到的服务器上的提交。这是手动运行的输出:
chris@IronHide:~$ /etc/cron.hourly/auto-commit
[master 8dc5299] Commit message
4 files changed, 8 insertions(+), 6 deletions(-)
rewrite 1h/1m/c.-b.-6.dat (100%)
Counting objects: 17, done.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (9/9), 4.64 KiB, done.
Total 9 (delta 3), reused 0 (delta 0)
To <repo_path_cencored>.git
6c6d0ad..8dc5299 master -> master
Run Code Online (Sandbox Code Playgroud)
不知道这是否重要,但我的 /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
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * 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 )
#
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
看起来当您手动运行脚本时,您将其作为chris. 那么你为什么要尝试root在 cron 下运行它呢?/etc/crontab(以及扩展/etc/cron.*目录)用于系统作业。要以您的用户身份运行作业,请运行crontab -e并编写如下一行
01 * * * * cd ~/path/to/directory && ~/bin/auto-commit
Run Code Online (Sandbox Code Playgroud)
这会~/bin/auto-commit在每小时一分钟后在指定目录中运行。
| 归档时间: |
|
| 查看次数: |
4093 次 |
| 最近记录: |