From: Ritu S. <sf...@us...> - 2005-08-01 12:18:54
|
Update of /cvsroot/smartfrog/core/components/ssh/src/org/smartfrog/services/ssh In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15818/src/org/smartfrog/services/ssh Modified Files: sshExec.sf SSHExecImpl.java Log Message: Modified for adding the logfile and for executing commands that are dependent on each other for setting the environment etc. Index: sshExec.sf =================================================================== RCS file: /cvsroot/smartfrog/core/components/ssh/src/org/smartfrog/services/ssh/sshExec.sf,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sshExec.sf 2 Jun 2005 12:50:45 -0000 1.2 --- sshExec.sf 1 Aug 2005 12:18:27 -0000 1.3 *************** *** 29,34 **** host extends String; username extends String; ! commands extends Vector; ! } --- 29,34 ---- host extends String; username extends String; ! commands extends Vector; ! logFile extends OptionalString; } Index: SSHExecImpl.java =================================================================== RCS file: /cvsroot/smartfrog/core/components/ssh/src/org/smartfrog/services/ssh/SSHExecImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SSHExecImpl.java 14 Jun 2004 12:01:42 -0000 1.2 --- SSHExecImpl.java 1 Aug 2005 12:18:38 -0000 1.3 *************** *** 20,26 **** package org.smartfrog.services.ssh; ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.FileWriter; import java.io.IOException; import java.io.StringReader; --- 20,25 ---- package org.smartfrog.services.ssh; ! import java.io.ByteArrayInputStream; ! import java.io.FileOutputStream; import java.io.IOException; import java.io.StringReader; *************** *** 29,32 **** --- 28,32 ---- import com.jcraft.jsch.ChannelExec; + import com.jcraft.jsch.ChannelShell; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; *************** *** 43,47 **** import org.smartfrog.sfcore.reference.Reference; import org.smartfrog.sfcore.logging.Log; ! /** * SmartFrog component to executes a command on a remote machine via ssh. --- 43,47 ---- import org.smartfrog.sfcore.reference.Reference; import org.smartfrog.sfcore.logging.Log; ! //import org.smartfrog.services.ssh.FilePasswordProvider; /** * SmartFrog component to executes a command on a remote machine via ssh. *************** *** 56,60 **** private static final int SSH_PORT = 22; private long timeout = 0; - private File outputFile = null; private boolean append = false; private String host; --- 56,59 ---- *************** *** 62,65 **** --- 61,65 ---- private String password; private int port = SSH_PORT; + private String logFile = null; private boolean failOnError = true; private UserInfoImpl userInfo; *************** *** 72,75 **** --- 72,76 ---- private Session session = null; private Log log; + /** * Constructs SSHExecImpl object. *************** *** 117,131 **** session.setTimeout((int) timeout); // Execute commands ! for (int i = 0 ; i <commandsList.size() ; i++ ) { ! final ChannelExec channel = (ChannelExec) session. ! openChannel("exec"); ! String cmd = (String) commandsList.get(i); ! log.info("Executing command:"+ cmd); ! channel.setCommand(cmd); ! channel.connect(); ! ! // wait for it to finish ! waitThread = new Thread() { public void run() { while (!channel.isEOF()) { --- 118,144 ---- session.setTimeout((int) timeout); + FileOutputStream tee = new FileOutputStream(logFile); // Execute commands ! ! StringBuffer buffer = new StringBuffer(); ! for (int i = 0 ; i <commandsList.size() ; i++ ) { ! String cmd = (String) commandsList.get(i); ! buffer.append(cmd); ! buffer.append("\n"); ! } ! ! byte[] bytes = buffer.toString().getBytes(); ! ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ! ! final ChannelShell channel = (ChannelShell) session.openChannel("shell"); ! channel.setOutputStream(tee); ! channel.setExtOutputStream(tee); ! channel.setInputStream(bais); ! channel.connect(); ! ! log.info("Executing commands:"+ buffer.toString()); ! ! // wait for it to finish ! waitThread = new Thread() { public void run() { while (!channel.isEOF()) { *************** *** 156,160 **** int exitStat = channel.getExitStatus(); if (exitStat != 0) { ! String msg = "Remote command: "+ cmd+ " failed with exit status " + exitStat; if (failOnError) { --- 169,173 ---- int exitStat = channel.getExitStatus(); if (exitStat != 0) { ! String msg = "Remote commands: "+ " failed with exit status " + exitStat; if (failOnError) { *************** *** 164,168 **** } waitThread = null; ! } // check if it should terminate by itself if(shouldTerminate) { --- 177,182 ---- } waitThread = null; ! channel.disconnect(); ! // check if it should terminate by itself if(shouldTerminate) { *************** *** 224,227 **** --- 238,242 ---- //optional attributes port = sfResolve(PORT, port, false); + logFile = sfResolve(LOG_FILE, logFile, false); timeout = sfResolve(TIMEOUT, timeout, false); failOnError = sfResolve(FAIL_ON_ERROR, failOnError, false); |