Rev 32337 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.service.SshServer;import com.jcraft.jsch.ChannelExec;import com.jcraft.jsch.JSch;import com.jcraft.jsch.Session;import org.springframework.stereotype.Service;@Servicepublic class SSHServiceImpl implements SSHService {@Overridepublic void executeCommand(String ipAddress, int port, String username, String password, String commandToExec) {try {JSch jsch = new JSch();Session session = jsch.getSession(username, ipAddress, port);session.setPassword(password);session.setConfig("StrictHostKeyChecking", "no");session.connect();// Restart serverChannelExec restartChannel = (ChannelExec) session.openChannel("exec");restartChannel.setCommand(commandToExec);//Reboot serverrestartChannel.connect();while (!restartChannel.isClosed()) {Thread.sleep(1000);}restartChannel.disconnect();session.disconnect();} catch (Exception e) {e.printStackTrace();}}}