Run SSH commands

Discussion in 'BungeeCord Plugin Development' started by ImFir3PvP, Jul 12, 2018.

  1. Hey,

    I really struggle how to execute ssh commands in BungeeCord.
    I want to code a CloudSystem and need to start the server.
    Jsch doesn´t worked or what shoud I do, to use Jsch.

    Thanks in advance.
     
  2. Try Runtime.getRuntime().exec()
     
  3. MiniDigger

    Supporter

    take a look at the java process api
    https://docs.oracle.com/javase/10/docs/api/java/lang/Process.html

    oh wait, you actually want to ssh into a remote server? that sounds wrong. Instead I would recommend that every host has a daemon running which are all connected to a master which then can issue commands to the daemons, like "start a server instance of this type with this map".
     
    • Agree Agree x 1
  4. Here is my method, that I tried to use, but it failed:

    String[] cmd = {"cd /home/SOLO-KnockOut/", "./start.sh"};
    runtimexec(p, cmd);

    private static void runtimexec(ProxiedPlayer p, String script) {
    try {
    Process proc = Runtime.getRuntime().exec(script);
    proc.waitFor();
    BufferedReader stdInput = new BufferedReader(
    new InputStreamReader(proc.getInputStream()));

    BufferedReader stdError = new BufferedReader(
    new InputStreamReader(proc.getErrorStream()));

    String s = null;
    while ((s = stdInput.readLine()) != null) {
    p.sendMessage(s);
    }

    while ((s = stdError.readLine()) != null)
    p.sendMessage(s);
    } catch (Exception e) {
    System.out.println(e.toString());
    }
    }
     

Share This Page