为了账号安全,请及时绑定邮箱和手机立即绑定

无法运行命令,内部有另一个命令

无法运行命令,内部有另一个命令

Go
人到中年有点甜 2022-10-04 16:23:13
抱歉,如果标题不是很不言自明,我正在尝试在一行中运行一个命令: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


查看完整回答
反对 回复 2022-10-04
  • 1 回答
  • 0 关注
  • 164 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号