抱歉,如果标题不是很不言自明,我正在尝试在一行中运行一个命令:sshProxyCommandssh -i /home/myuser/.ssh/myprivatekey.pem ec2-user@i-00xxxxxxxxxx -o ProxyCommand="aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"上面的这个命令有效,但是我需要在go中做同样的事情。func (s SSH) Tunnel() error { parts := strings.Fields(`ssh -i /home/myuser/.ssh/myprivateksy.pem ec2-user@i-00xxxxxxxxxxx`) parts = append(parts, `-o ProxyCommand="aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"`) command := exec.Command(parts[0], parts[1:]...) command.Stderr = os.Stderr command.Stdout = os.Stdout command.Stdin = os.Stdin return command.Run()}但是我得到了这个错误:zsh:1: command not found: aws ssm start-session --target i-00Xxxxxxxxxxxx --document-name AWS-StartSSHSession --parameters 'portNumber=22'我试图把它包含在:strings.Fieldsparts := strings.Fields(`ssh -i /home/myuser/.ssh/myprivateksy.pem ec2-user@i-00xxxxxxxxxxx -o ProxyCommand="aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"`)但是,我有另一个错误:zsh:1: unmatched " 我怎样才能做到这一点?
1 回答

拉丁的传说
TA贡献1789条经验 获得超8个赞
根据您提供的 shell 输入,以下各项应该有效:
parts := strings.Fields(`ssh -i /home/myuser/.ssh/myprivateksy.pem ec2-user@i-00xxxxxxxxxxx -o`)
parts = append(parts, `ProxyCommand=aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'`)
这将作为没有引号的单个参数传递后面的部分。外壳处理将删除这些引号。-o
- 1 回答
- 0 关注
- 164 浏览
添加回答
举报
0/150
提交
取消