package com.migibert.kheo.core;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.migibert.kheo.client.SshClient;

public abstract class AbstractSshCommand<T> implements SshCommand<T> {

    private Logger logger;
    private String command;

    protected AbstractSshCommand(String command) {
        this.command = command;
        this.logger = LoggerFactory.getLogger(this.getClass());
    }

    public T executeAndParse(Server target) throws IOException {
        logger.info("Executing {} on {}", command, target.host);
        String result = execute(target, command);
        logger.info("Result is {}", result);
        return parse(result);
    }

    @Override
    public String execute(Server target, String command) throws IOException {
        if (target.sudo) {
            logger.info("Executing remote command with sudo flag");
            command = "echo " + target.password + " | sudo -kS " + command;
        }
        return SshClient.execute(target, command);
    }
}

@@ -916,16 +916,17 @@
 = %22echo 
+'
 %22 + targ
@@ -940,16 +940,17 @@
 word + %22
+'
  %7C sudo 

Fix password character escaping issue