I am trying to execute a Shell Script by using below code but this is trying run the Shell Script in my local system although I have provided the Shell Script location of my Remote Linux server . I do not have any idea why it is working like that . Can any one check where is the problem .
import java.io.InputStream;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
import com.jcraft.jsch.*
import java.io.*
import java.lang.*
JSch jsch = new JSch();
Session session = jsch.getSession("admin","192.168.2.32", 22);
session.setPassword("admin123");
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect()
Channel channel = session.openChannel("exec");
channel.connect();
def command = "bash /home/Soapui_Automation/test.sh"
def process = command.execute()
def outputStream = new StringBuffer()
def errorStream = new StringBuffer()
process.consumeProcessOutput(outputStream ,errorStream)
process.waitFor()
log.info("return code: ${process.exitValue()}")
log.error("standard error: ${process.err.text}")
log.info("standard out: ${process.in.text}" + outputStream.toString())
channel.disconnect();
session.disconnect();
Response:
Thu Jan 28 15:00:18 IST 2016:INFO:return code: 1
Thu Jan 28 15:00:18 IST 2016:ERROR:standard error:
Thu Jan 28 15:00:18 IST 2016:INFO:standard out:
Thanks Pritish Panda