我需要通过C#通过SSH在docker容器中运行多个命令。我正在使用Renci.sshnet进行ssh连接。这是我的代码:
{
ssh.Connect();
var command = ssh.CreateCommand("sudo docker exec - it freeradius bash &&"+" echo User-Name=" + username + ",Framed-IP-Address=" + framedipaddress + "| radclient -x " + nasipaddress + ":1700 disconnect a1rp0c9ptio8");
strReturn = command.Execute().ToString();
}
如果我手动进行操作,这两行命令对我来说效果很好。但是从ssh无法正常工作...请知道吗???
答案 0 :(得分:0)
您可以在bash参数-c
中设置完整的命令:
$ docker exec -it sad_kilby bash -c "echo 123 && echo $? && ls / | grep etc"
123
0
etc
所以您的命令将如下所示:
string subcommand = "echo User-Name=" + username + ",Framed-IP-Address=" + framedipaddress + "| radclient -x " + nasipaddress + ":1700 disconnect a1rp0c9ptio8"
var command = ssh.CreateCommand("sudo docker exec -it freeradius bash -c \"" + subcommand + "\"")