使用Plink执行(sudo)子命令 [英] Executing (sudo) subcommands using Plink

查看:251
本文介绍了使用Plink执行(sudo)子命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Window PowerShell命令Linux机器。命令取决于之前的命令失败/通过。因此,我必须将所有命令放在一起。我尝试了多种将命令组合在一起的方法,但是最后我只收到第一个命令的输出。

I am trying to command Linux machine from Window PowerShell. The commands are dependent on the fail/pass of the commands before. Therefore, I have to put all the commands together. I have tried multiple ways of putting commands together but at the ends I only receive the output of the first command.

PS C:\Users\sams> plink -ssh -l username -pw root username@10.223.26.34 -t
      "sudo -i && cd /root/docker/storm-supervisor/ && ./stop-all.sh"

实际结果:仅接收第一个命令的输出。

The actual result: Only receives the output of the first command.

预期结果:接收最终命令的输出。

Expected result: Receives output of the final command.

推荐答案


sudo -i && cd /root/docker/storm-supervisor/ && ./stop-all.sh


在Linux shell中尝试命令。它也不起作用。它将执行提升的外壳程序,并等待您键入命令。只有在离开 sudo shell之后,它才会运行其他命令(使用原始帐户)。

Try your command in Linux shell. It won't work either. It will execute an elevated shell and wait for you to type commands. Only after you leave sudo shell, it will run the other commands (using the original account).

cd ./ stop-all.sh sudo 的子命令。


  • 最好的方法是在 sudo 命令行:

  sudo "cd /root/docker/storm-supervisor/ && ./stop-all.sh"

但这可能需要修改 sudoers 文件。

But that will probably require modifications of the sudoers file. Though it's the right way.

否则,您将需要将命令提供给 sudo 输入:

Or you will need to feed the commands to sudo input:

  echo "cd /root/docker/storm-supervisor/ && ./stop-all.sh && exit" | sudo



  • 或将所有内容提供给Plink输入:

  • Or feed everything to Plink input:

    (
      echo cd /root/docker/storm-supervisor/
      echo ./stop-all.sh
    ) | plink -ssh -l username -pw root username@10.223.26.34 -t sudo -i
    



  • 甚至:

  • Or even:

    (
      echo sudo -i
      echo cd /root/docker/storm-supervisor/
      echo ./stop-all.sh
    ) | plink -ssh -l username -pw root username@10.223.26.34 -t
    



  • 这篇关于使用Plink执行(sudo)子命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆