find: git: No such file or directory 通过 crontab 中的脚本

find: git: No such file or directory through script in crontab

我正在尝试在 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

有人吗?

如您在 http://man.cx/crontab(5) 中所见,PATH 环境变量设置为 /usr/bin:/bin。如果 git 不在这些地方之一,您的脚本将找不到它。如果你想要自己的 PATH 环境变量集,你可以配置它,或者你使用在 PATH.

中找不到的可执行文件的绝对路径

还有其他方法可以做到这一点,但因为我只有 git 有问题,所以我做了,

which git

找出它的位置,然后将位置添加到 git、

find . -type d -depth 1 -exec /usr/local/git/bin/git --git-dir={} --work-tree=$PWD/{} fetch origin \; >> git_backup_update.log 2>&1