如何将请求登录到"exec"中/从中注销



我的GitLab CE服务器上有这个git预接收挂钩:

#!/bin/sh
# This is the single source of truth for where Gitaly's embedded Git hooks are.
exec "$GITALY_BIN_DIR/gitaly-hooks" "$(basename $0)" "$@"

我对这个exec命令中传递的内容非常感兴趣,因为它"不起作用"。

如何捕获exec命令的输入和输出,并将其记录到一个或多个文件中?非常感谢。

这是为了对输出进行T形连接,但有一个syntax error: redirection unexpected。我还想记录输入。

exec "$GITALY_BIN_DIR/gitaly-hooks" "$(basename $0)" "$@"  &> >(tee -a /var/log/git-as-svn/pre-receive.2.3.log)

请参阅https://docs.gitlab.com/ee/administration/server_hooks.html特别是自定义错误消息

另请参阅调试git挂钩的最佳方法

您可以将第一行从#!/bin/sh更改为#!/bin/sh -x

或者,您可以按照user1934428的建议将$@的值写入一个文件。


对不起,我没有仔细阅读这个问题。使用strace怎么样,然后你可以看到输入和输出是什么?

例如:

$ cat test.sh                                                                                                                          #!/bin/sh
/usr/bin/strace -f -o /tmp/strace.out -s 9999 /bin/bash -c "exec ./hello.sh"
$ cat hello.sh                                                                                                                         #!/bin/sh
echo What is your name?
read name
echo hello $name
$ ./test.sh                                                                                                                            What is your name?
John
hello John
$ grep read(0 /tmp/strace.out                                                                                                         
104   read(0, "J", 1)                   = 1
104   read(0, "o", 1)                   = 1
104   read(0, "h", 1)                   = 1
104   read(0, "n", 1)                   = 1
104   read(0, "n", 1)                  = 1
$ grep write( /tmp/strace.out                                                                                                         
104   write(1, "What is your name?n", 19) = 19
104   write(1, "hello Johnn", 11)      = 11
$                                

最新更新