【问题标题】:find: git: No such file or directory through script in crontab找到:git:通过crontab中的脚本没有这样的文件或目录
【发布时间】: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

有人吗?

【问题讨论】:

  • 调整您的PATHcron 的流行实现允许在 crontab 中设置环境变量:PATH=/bin:/usr/bin:...。或者,将绝对路径传递给git,例如/usr/bin/git
  • 感谢 Ruslan,这是一种方法,我已经创建了 'which git' 并发现了位置,然后将其添加到脚本中。

标签: git shell find crontab


【解决方案1】:

正如您在http://man.cx/crontab(5) 中看到的,PATH 环境变量设置为/usr/bin:/bin。如果git 不在这些地方之一,您的脚本将找不到它。如果您想要自己的PATH 环境变量集,您可以对其进行配置,或者使用在PATH 中找不到的可执行文件的绝对路径。

【讨论】:

    【解决方案2】:

    还有其他方法可以做到这一点,但由于我只有 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
    

    【讨论】:

      猜你喜欢
      • 2017-08-06
      • 2014-05-23
      • 2016-01-11
      • 2017-06-16
      • 2018-08-24
      • 2019-08-23
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      相关资源
      最近更新 更多