【发布时间】:2017-05-02 05:58:20
【问题描述】:
我正在尝试创建一个在 crontab 中运行的脚本,但是当我尝试在 crontab 守护程序下使用它时,我遇到了命令位置问题。
已经对该脚本进行了一些测试,似乎工作正常。
这里是:
# I add this cd because of crontab location
cd ~/Documents/gitrepobackup/
find . -type d -depth 1 -exec git --git-dir={} --work-tree=$PWD/{} fetch origin \; >> git_backup_update.log 2>&1
这是我在该日志中收到的输出:
find: git: No such file or directory
这也是我在crontab中添加的条目:
* * * * * ~/Documents/gitrepobackup/git_backup_update.sh
有人吗?
【问题讨论】:
-
调整您的
PATH。cron的流行实现允许在 crontab 中设置环境变量:PATH=/bin:/usr/bin:...。或者,将绝对路径传递给git,例如/usr/bin/git -
感谢 Ruslan,这是一种方法,我已经创建了 'which git' 并发现了位置,然后将其添加到脚本中。