I am able to execute Shell script command Soap UI and not sure how to read and store the echo output to a variable.
test1.sh contains below commands
CURRENTDATEONLY=`date +"%b %d, %Y"`
echo Current Date is: ${CURRENTDATEONLY}
sleep 10
I am able to execute Shell script command Soap UI and not sure how to read and store the echo output to a variable.
I have tried below code, still not capturing the output.
def command = "C:/Program Files (x86)/PuTTY/putty.exe -ssh user@ip -pw pass  -m C:/test1.sh"
def Process p = Runtime.getRuntime().exec(command);
p.waitFor()
BufferedReader is1 =   new BufferedReader(new InputStreamReader(p.getInputStream())); 
log.info is1
        String line; 
        // reading the output 
        while ((line = is1.readLine()) != null) 
     log.info line ;
====================================================
Tried using jsch api as well, but no luck
import com.jcraft.jsch.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
        String user = "";
        String pw = "";
        String host = "";
        int port = 22;
        String remoteFile = "C:/test1.sh";
        try {
            JSch jsch = new JSch();
            Session session = jsch.getSession(user, host, port);
            session.setPassword(pw);
            //session.setConfig("StrictHostKeyChecking", "no");
            log.info("Establishing Connection...");
            session.setTimeout(60000);
            session.connect();
            log.info("Connection established.");
            log.info("Crating SFTP Channel.");
            ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
            sftpChannel.connect();
            log.info("SFTP Channel created.");
            InputStream inputStream = sftpChannel.get(remoteFile);
            Scanner scanner = new Scanner(new InputStreamReader(inputStream)) 
                while (scanner.hasNextLine()) {
                    String line = scanner.nextLine();
                    log.info(line);
                }
        } catch (JSchException | SftpException e) {
            e.printStackTrace();
        }
Expectation is to read and store CURRENTDATEONLY variable to properties