【问题标题】:Error: bad line length character while executing a forced command script after git command错误:在 git 命令后执行强制命令脚本时出现错误的行长字符
【发布时间】:2016-07-25 03:44:56
【问题描述】:

我编写了一个强制命令脚本,必须通过 ssh 为每个 git 命令执行该脚本。所以,我在服务器端的 /.ssh/authorized_keys 中添加了这一行:

command="/bin/wrapper.sh",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa....

然后我将 wrapper.sh 文件放在 bin 文件夹中,代码如下:

#!/bin/sh
echo -n "Execute the git command? (y/n)?"
read answer
if echo "$answer" | grep -iq "^y" ;then
    exec git-shell -c "$SSH_ORIGINAL_COMMAND"
else
    echo Goodbye
fi

所以,当我在客户端启动任何 git 命令时,例如 git push origin master,我会收到以下错误:

fatal: protocol error: bad line length character: Exec

我该如何解决?我注意到一个 not git 命令,例如:

ssh User@myhost ls

脚本运行正常。

【问题讨论】:

    标签: git ssh sh


    【解决方案1】:

    当您使用git 而不是ssh 时,您的本地git 将不允许您与脚本进行交互。它正在使用它的协议,第一个 echo 将破坏协议(因此出现错误)。

    如果它可以那样工作就好了,但事实并非如此。

    【讨论】:

    • 谢谢!我怀疑它。你知道另一种在服务器端自定义 git 命令的方法吗?
    猜你喜欢
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多