【问题标题】:git post receive hooks run remote server shell script error expecting keyword_dogit post receive hooks run remote server shell script error expecting keyword_do
【发布时间】:2019-03-14 04:17:39
【问题描述】:

在下面的帖子接收钩子下,我推送到存储库后确实收到错误,remote: hooks/post-receive:: syntax error, unexpected $undefined, expecting keyword_do or '{' or '('

发布接收脚本如下,

#!bin/bash while read oldrev newrev ref \ do ssh user1@ip -pPassword\ 'path/to/the/shell.sh' end

在这种情况下,我的远程服务器密码包括\,我尝试如下

#!bin/bash while read oldrev newrev ref do ssh user1@ip -pPassword\ 'path/to/the/shell.sh' end

#!bin/bash while read oldrev newrev ref \ do (ssh user1@ip -pPassword\ 'path/to/the/shell.sh'); end

【问题讨论】:

  • 通过自己运行手动测试您的接收后脚本。如果需要,请给它示例输入,尽管出现这种语法错误,您通常会在它尝试读取任何内容之前得到语法错误。
  • @Sadzone 这几乎肯定是来自您的shell.sh 的错误消息,所以您应该向我们展示。

标签: git shell githooks


【解决方案1】:

对于 bash 中的 while 循环,您可以:

#!/bin/bash
while read oldrev newrev ref;do
    echo $read $oldrev $newrev $ref
done

#!/bin/bash
while read oldrev newrev ref
do
    echo $read $oldrev $newrev $ref
done

#!/bin/bash
while read oldrev newrev rev;do echo $read $oldrev $newrev $ref;done

我不确定ssh 部分是否正确,但我认为\ 没有必要。

【讨论】:

  • 这些都不适用于我的情况,我确实遇到了同样的错误,包括syntax error, unexpected end-of-input, expecting keyword_end
【解决方案2】:

我不确定 ssh 部分是否正确

实际上,ssh 可能有效,但也是问题的一部分:

  • 检查ssh -T user1@ip -pPassword 在从接收后挂钩所在的服务器执行时是否工作
  • 检查是否有效静默,这意味着 user1 .bashrc.profile 不会回显一堆字符串,这可能会干扰钩子的执行。

【讨论】:

    猜你喜欢
    • 2012-06-03
    • 2017-08-14
    • 2013-04-14
    • 1970-01-01
    • 2014-06-02
    • 2014-09-05
    • 2013-03-29
    • 2012-04-16
    • 2013-07-17
    相关资源
    最近更新 更多