gpt4 book ai didi

linux - 退出嵌套 shell 后 ssh 脚本命令丢失

转载 作者:太空宇宙 更新时间:2023-11-04 10:23:10 26 4
gpt4 key购买 nike

我正在通过 ssh 执行脚本,如下所示:

ssh $USER@somehost 'bash -s' < ./myscript.sh

内部myscript.sh :

echo '1'
sudo -i -u svcacct # use the service account
echo '2'
exit # last working command
echo '3'
exit
echo '4'

输出:

shellA$ 1
shellB$ 2
shellA$

如您所见,exit命令,在正确退出内部 session 的同时,阻止了后续脚本命令的运行。 ssh 连接挂起(Ctrl-C 退出)。我该如何解决这个问题?

最佳答案

一个有效的实现,发出 123,看起来像:

echo '1'
sudo -u svcacct -i bash -s <<'EOF-1'
echo '2'
EOF-1
echo '3'
exit
echo '4'

请注意,我们依赖于任何程序退出,留下 stdin 的文件描述符以及任何特定内容排队等待读取,而是提供 svcacct 实例,只有来自不同 heredoc 的标准输入的非常有限和特定的子集。

关于linux - 退出嵌套 shell 后 ssh 脚本命令丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42961883/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com