博士
命令git fetch origin [branch-name]在脚本中调用时不起作用,而是在从shell调用时起作用。
脚本和终端都可以在另一个盒子上正常工作。盒子就在一个公司代理的后面。
我假设与shell相比,脚本中的环境有一些不同。
How我可以让这个命令在脚本中运行吗?
在将存储库迁移到GitHub之前,所有东西都可以在这两个框上工作。这两个系统的起源都作了相应的更新。开发系统立即开始工作,而暂存系统则无法工作。
这是脚本部分的样子,它在实际启动之前检查所有存储库,并在此结束:
check_git_connection_mapbender() {
cd ${installation_folder}mapbender
git fetch origin ${git_mapbender_repositoryBranch} &>/dev/null
if [ $? -ne 0 ]; then
echo "Fetching Mapbender repository failed!"
echo "Abording update..."
exit 1
fi
set_git_filemode_config
}两个echo行被回显,脚本退出。变量都设置好了。
由于我怀疑环境变量存在一些问题,所以我试图直接从终端调用失败的命令git fetch origin [branch-name]。当从shell调用时,该命令在所有情况下都有效:
me@box:/path/to/repo$ git fetch origin [branch-name]me@box:/path/to/repo$ sudo git fetch origin [branch-name]me@box:$ sudo -i cd /path/to/repo && git fetch origin [branch-name]me@box:$ sudo su - -> root@box: cd /path/to/repo && git fetch origin [branch-name]似乎不起作用的是以下方式:
me@box:$ sudo -i-> root@box: cd /path/to/repo && git fetch origin [branch-name] <--这会引发类似于脚本中的错误首先,我保证在这两个系统上有效的git配置是相同的。
从那时起,我尝试在暂存系统上添加某些选项来解决问题,但没有成功。
我试着设置:
url.http://.insteadof=https://http.https://github.com.sslverify=falsehttp.proxyhttps.proxyhttp.sslCert因为它帮不上忙,我又把它移走了。
我将export GIT_TRACE_CURL=true添加到脚本中,因此如下所示:
check_git_connection_mapbender() {
cd ${installation_folder}mapbender
# DEBUG
export GIT_TRACE_CURL=true
source /etc/environment
echo $http_proxy
echo $https_proxy
# END DEBUG
echo $git_mapbender_repositoryBranch
git fetch origin ${git_mapbender_repositoryBranch} # &>/dev/null
if [ $? -ne 0 ]; then
echo "Fetching Mapbender repository failed!"
echo "Abording update..."
exit 1
fi
set_git_filemode_config
}..。输出是
[correct http_proxy environment variable]
[correct https_proxy environment variable]
[correct branch name]
16:52:17.600248 http.c:599 == Info: Couldn't find host github.com in the .netrc file; using defaults
16:52:17.603973 http.c:599 == Info: Trying 140.82.121.4...
16:52:17.604035 http.c:599 == Info: TCP_NODELAY set
16:52:17.605297 http.c:599 == Info: connect to 140.82.121.4 port 443 failed: Verbindungsaufbau abgelehnt
16:52:17.605372 http.c:599 == Info: Failed to connect to github.com port 443: Verbindungsaufbau abgelehnt
16:52:17.605386 http.c:599 == Info: Closing connection 0
fatal: unable to access 'https://github.com/LVGL-SL/mapbender-sl.git/': Failed to connect to github.com port 443: Verbindungsaufbau abgelehnt
Fetching Mapbender repository failed!
Abording update...我被告知,系统应该受到相同的防火墙规则集,因为有一个子网。
发布于 2021-08-27 15:04:21
盒子就在一个公司代理的后面。无法在github.com文件中找到主机.netrc;使用默认连接到140.82.121.4端口443失败: Verbindungsaufbau abgelehnt脚本使用sudo运行并失败,但是命令git fetch源将在终端中工作
猜测:您的公司代理需要存储在用户帐户下某个地方的凭据,可能存储在.netrc文件中。
如果以普通用户的身份运行git命令,它将访问这些凭据。
如果您以root身份运行脚本,它将在root的主目录中查找凭据,找不到它们,因此失败。
您可以通过从终端运行带有sudo的git命令来验证;如果以上原因是原因,它也会失败。
要解决您的问题,您需要解释为什么要将脚本作为根用户运行,它需要普通用户的证书才能访问github (这听起来像是一个应该首先解决的基本设计问题)。根据解释,您可以为代理(不明智)提供根凭据,在脚本中模拟特定用户来执行git命令,或者(这是最好的变体)修复任何需要根访问的内容,这样它就不需要根访问,并且可以作为普通用户运行。
https://unix.stackexchange.com/questions/666518
复制相似问题