Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

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.

like image 962
mike23 Avatar asked May 11 '12 06:05

mike23


2 Answers

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.sh containing :

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

And then create a new Build System in ST2 to call it :

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

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

like image 137
mike23 Avatar answered Sep 22 '22 07:09

mike23


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

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

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

I use it for remote make, works quite good.

Note that 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 PuttyGen and autologin.

like image 26
st4nson Avatar answered Sep 20 '22 07:09

st4nson