Hello,
I started working on this recently and got into a trouble. Please help me on how to execute a shell script using a java service written in webMethods service development.
So far my progress is as follows:
I was able to login using ssh…verified on the unix shell and it is working.
I am unable to do the following.
cd to a specific directory and
invoke the shell script.
public static final void invokeOScommand(IData pipeline)
throws ServiceException {
IDataCursor idc = pipeline.getCursor();
long connectionTimeout = 600;
long readTimeOut = 600;
String hostname = IDataUtil.getString( idc, “hostname” );
String username = IDataUtil.getString( idc, “username” );
String password = IDataUtil.getString( idc, “password” );
String command = IDataUtil.getString( idc, “command” );
//String commands = {“su - vkb”,“sh”};
String directory = IDataUtil.getString( idc, “directory” );
String curr_status= null;
try{
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
SshParameters sshParams = new SshParameters (hostname,username,password);
Ssh ssh = new Ssh(sshParams);
ssh.connect();
String status = "OK,Connected";
// get OutputStream
OutputStream out = ssh.getOutputStream();
// define command to perform directory listing
command = "sh startup.sh";
// send command to SSH server
out.write(command.getBytes());
// write CRLF to indicate end of command
out.write("\r\n".getBytes());
IDataUtil.put( idc, "ssh_object", ssh );
IDataUtil.put( idc, "status", status );
}
catch (Exception e) {
throw new ServiceException("SystemLogger: Could not resolve syslog host. [java.net.UnknownHostException]");
}
#webMethods#Integration-Server-and-ESB