dongxing9219 2017-10-26 10:03
浏览 125
已采纳

通过exec.Command使用rsh选项运行rsync

I'm invoking rsh in go exec.Command:

rsh := fmt.Sprintf("--rsh=\"/usr/bin/ssh -p %s -o StrictHostKeyChecking=no -l %s\"", *destPort, *destUserName)
cmd := exec.Command("rsync", "-avz", rsh, from, fmt.Sprintf("%s:%s", *destHost, to))
fmt.Println(cmd)
var outb, errb bytes.Buffer
cmd.Stdout = &outb
cmd.Stderr = &errb

err = cmd.Run()
fmt.Println(outb.String())
fmt.Println(errb.String())

And I'm getting this error:

rsync: Failed to exec /usr/bin/ssh -p 1999 -o StrictHostKeyChecking=no -l root: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(84) [sender=3.0.9]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in IPC code (code 14) at io.c(605) [sender=3.0.9]

Tried to explicitly set the full path of ssh in rsh.

The output of fmt.Println(cmd) seems correct:

&{/usr/bin/rsync [rsync -avz --rsh="/usr/bin/ssh -p 1999 -o StrictHostKeyChecking=no -l root" /var/www/html/atlaserpsolution.com/production/altractors h3.ftp.datagix.com:/var/www/vhosts/atlas.ns513.datagix.com/atlaserp/documents/altractors] []  <nil> <nil> <nil> [] <nil> <nil> <nil> <nil> <nil> false [] [] [] [] <nil> <nil>}

What's wrong with my exec.Command?

  • 写回答

1条回答 默认 最新

  • dty63504 2017-10-26 10:06
    关注

    You are merging two arguments into one (--rsh and /usr/bin/ssh ...). Split them and it should work:

    rsh := fmt.Sprintf("/usr/bin/ssh -p %s -o StrictHostKeyChecking=no -l %s", *destPort, *destUserName)
    cmd := exec.Command("rsync", "-avz", "--rsh", rsh, from, fmt.Sprintf("%s:%s", *destHost, to))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?