bash Sublime text 2 - 如何通过 ssh 运行 shell 命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10546739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:15:16  来源:igfitidea点击:

Sublime text 2 - How to run a shell command over ssh?

basheditorsublimetext2

提问by mike23

I'm new to Sublime Text 2and there's something I haven't figured out yet, how can I run a bash command over SSH ?

我是Sublime Text 2 的新手,但我还没有弄清楚,如何通过 SSH 运行 bash 命令?

For example, to view the Apacheerror log on my dev server, I'd like to be able to run :

例如,要查看我的开发服务器上的Apache错误日志,我希望能够运行:

ssh [email protected] "tail -10 /var/log/httpd-error-user.log"

Instead of having to open a terminal, I'd like to run this from within the editor with a keyboad shortcut.

我不想打开终端,而是想使用键盘快捷键从编辑器中运行它。

I've read about build systems, but I'm not sure it's the way to go, also it seems to allow only one command.

我读过关于build systems,但我不确定这是要走的路,而且似乎只允许一个命令。

回答by mike23

I'll answer my own question. You can easily create a build pointing to any script, so all I had to do was create myscript.shcontaining :

我会回答我自己的问题。您可以轻松创建指向任何脚本的构建,因此我所要做的就是创建myscript.sh包含:

#!/bin/bash
ssh [email protected] "tail -10 /var/log/httpd-error-user.log" 

And then create a new Build Systemin ST2to call it :

然后在ST2 中创建一个新的构建系统来调用它:

{
    "cmd": ["./myscript.sh"]
}

Note: In this example (i'm on Linux), myscript.shis located in /home/mike/.config/sublime-text-2/Packages/User/

注意:在这个例子中(我在 Linux 上),myscript.sh位于/home/mike/.config/sublime-text-2/Packages/User/

回答by st4nson

If You are on a windows machine, You could try this:

如果你在 Windows 机器上,你可以试试这个:

  1. Install Putty. You we'll need plinkfrom this package.
  2. Update Your PATHvariable with Putty install directory.
  3. Create a Build System in Sublime

    {
     "cmd": ["plink", "-pw", "<password>", "<userid>@<remotehost>", "./your-script.sh"]
    }
    
  1. 安装腻子。我们需要你plink从这个包中。
  2. PATH使用 Putty 安装目录更新您的变量。
  3. 在 Sublime 中创建构建系统

    {
     "cmd": ["plink", "-pw", "<password>", "<userid>@<remotehost>", "./your-script.sh"]
    }
    

I use it for remote make, works quite good.

我用它远程make,效果很好。

Notethat your password is plain text here. I know it's no good ;]. This is just an example. To fix it keybased login could be used. Google PuttyGenand autologin.

请注意,您的密码在这里是纯文本。我知道这不好;]。这只是一个例子。要修复它,可以使用基于密钥的登录。谷歌PuttyGen和自动登录

回答by Michael Le

Have you tried looking into Sublime SFTPplugin?

您是否尝试过查看Sublime SFTP插件?