[Resolved]Executing remote Unix Script
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2010
07:41 AM
03-30-2010
07:41 AM
[Resolved]Executing remote Unix Script
I've been doing some research and have been unsuccessful in executing a command on a remote Unix server through SoapUI. I've seen some recommendations using Pure Java, but was obviously hoping to leverage SoapUI's existing Features.
Anyone have any ideas or experience on this?
Anyone have any ideas or experience on this?
4 REPLIES 4
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2010
01:22 PM
04-02-2010
01:22 PM
I was able to figure it out by utilizing JSCH.
Groovy Script below, visit http://www.jcraft.com/jsch/ to download jsch-0.1.42.jar.
I abstracted this whole thing to a 'utility' test case I can call with parameters.
package com.content.jsc;
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
public static class MyUserInfo implements UserInfo{
String password = "";
public MyUserInfo(String password) { this.password = password; }
public String getPassword(){ return password; }
public boolean promptYesNo(String str){return true;}
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){ return true; }
public boolean promptPassword(String message){ return true; }
public void showMessage(String message){}
}
def mode = context.expand( '${#TestCase#RUN_MODE}' )
def wacssid = context.expand( '${#TestCase#WACS_SID}' )
def date = context.expand( '${#TestCase#DATE}' )
def pwd = context.expand( '${#TestCase#PASSWORD}' )
def host = context.expand( '${#TestCase#HOSTNAME}' )
def command = context.expand( '${#TestCase#COMMAND}' )
JSch jsch=new JSch();
session=jsch.getSession(wacssid,host,22)
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo(pwd);
session.setUserInfo(ui);
session.connect();
Channel channel=session.openChannel("exec");
//log.info(mode)
((ChannelExec)channel).setCommand("/u01/wacsapp/"+wacssid+"/MDM/bin/"+command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
instream=channel.getInputStream();
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(instream.available()>0){
int i=instream.read(tmp, 0, 100);
if(i<0)break;
log.info(new String(tmp, 0, i));
}
if(channel.isClosed()){
log.info("exit-status: "+channel.getExitStatus());
if (channel.getExitStatus()!=0)
throw new Exception( "Script "+command+" Failed" );
break;
}
try{Thread.sleep(1000);}catch(Exception ee){ log.info(ee); }
}
channel.disconnect();
session.disconnect();
Groovy Script below, visit http://www.jcraft.com/jsch/ to download jsch-0.1.42.jar.
I abstracted this whole thing to a 'utility' test case I can call with parameters.
package com.content.jsc;
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
public static class MyUserInfo implements UserInfo{
String password = "";
public MyUserInfo(String password) { this.password = password; }
public String getPassword(){ return password; }
public boolean promptYesNo(String str){return true;}
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){ return true; }
public boolean promptPassword(String message){ return true; }
public void showMessage(String message){}
}
def mode = context.expand( '${#TestCase#RUN_MODE}' )
def wacssid = context.expand( '${#TestCase#WACS_SID}' )
def date = context.expand( '${#TestCase#DATE}' )
def pwd = context.expand( '${#TestCase#PASSWORD}' )
def host = context.expand( '${#TestCase#HOSTNAME}' )
def command = context.expand( '${#TestCase#COMMAND}' )
JSch jsch=new JSch();
session=jsch.getSession(wacssid,host,22)
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo(pwd);
session.setUserInfo(ui);
session.connect();
Channel channel=session.openChannel("exec");
//log.info(mode)
((ChannelExec)channel).setCommand("/u01/wacsapp/"+wacssid+"/MDM/bin/"+command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
instream=channel.getInputStream();
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(instream.available()>0){
int i=instream.read(tmp, 0, 100);
if(i<0)break;
log.info(new String(tmp, 0, i));
}
if(channel.isClosed()){
log.info("exit-status: "+channel.getExitStatus());
if (channel.getExitStatus()!=0)
throw new Exception( "Script "+command+" Failed" );
break;
}
try{Thread.sleep(1000);}catch(Exception ee){ log.info(ee); }
}
channel.disconnect();
session.disconnect();
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2010
10:56 PM
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2010
05:54 AM
09-22-2010
05:54 AM
So once you download the jsch jar file, where do i save it? I mean in which location?
should it be under this directory -- C:\Program Files\eviware\soapUI-Pro-3.0.1\.install4j ?
should it be under this directory -- C:\Program Files\eviware\soapUI-Pro-3.0.1\.install4j ?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2010
11:18 PM
09-28-2010
11:18 PM
Figured it out. The file needs to be saved under the following directory,
C:\Program Files\eviware\soapUI-Pro-3.0.1\lib
Once done right click on the file - > properties and then click on Unblock (if it is blocked).
Following is the the groovy script which works fine on my box,
package com.content.jsc;
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
public static class MyUserInfo implements UserInfo{
String password = "";
public MyUserInfo(String password) { this.password = password; }
public String getPassword(){ return password; }
public boolean promptYesNo(String str){return true;}
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){ return true; }
public boolean promptPassword(String message){ return true; }
public void showMessage(String message){}
}
def mode = context.expand( '${#TestCase#RUN_MODE}' )
def username = "xxxxxxx"
def date = context.expand( '${#TestCase#DATE}' )
def pwd = "xxxxxxx"
def host = "xxxxxxx"
def command = "sh santosh.sh"
JSch jsch=new JSch();
session=jsch.getSession(username,host,22)
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo(pwd);
session.setUserInfo(ui);
session.connect();
Channel channel=session.openChannel("exec");
log.info(mode)
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
instream=channel.getInputStream();
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(instream.available()>0){
int i=instream.read(tmp, 0, 100);
if(i<0)break;
log.info(new String(tmp, 0, i));
}
if(channel.isClosed()){
log.info("exit-status: "+channel.getExitStatus());
if (channel.getExitStatus()!=0)
throw new Exception( "Script "+command+" Failed" );
break;
}
try{Thread.sleep(1000);}catch(Exception ee){ log.info(ee); }
}
channel.disconnect();
session.disconnect();
C:\Program Files\eviware\soapUI-Pro-3.0.1\lib
Once done right click on the file - > properties and then click on Unblock (if it is blocked).
Following is the the groovy script which works fine on my box,
package com.content.jsc;
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
public static class MyUserInfo implements UserInfo{
String password = "";
public MyUserInfo(String password) { this.password = password; }
public String getPassword(){ return password; }
public boolean promptYesNo(String str){return true;}
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){ return true; }
public boolean promptPassword(String message){ return true; }
public void showMessage(String message){}
}
def mode = context.expand( '${#TestCase#RUN_MODE}' )
def username = "xxxxxxx"
def date = context.expand( '${#TestCase#DATE}' )
def pwd = "xxxxxxx"
def host = "xxxxxxx"
def command = "sh santosh.sh"
JSch jsch=new JSch();
session=jsch.getSession(username,host,22)
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo(pwd);
session.setUserInfo(ui);
session.connect();
Channel channel=session.openChannel("exec");
log.info(mode)
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
instream=channel.getInputStream();
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(instream.available()>0){
int i=instream.read(tmp, 0, 100);
if(i<0)break;
log.info(new String(tmp, 0, i));
}
if(channel.isClosed()){
log.info("exit-status: "+channel.getExitStatus());
if (channel.getExitStatus()!=0)
throw new Exception( "Script "+command+" Failed" );
break;
}
try{Thread.sleep(1000);}catch(Exception ee){ log.info(ee); }
}
channel.disconnect();
session.disconnect();
