Hi, We are trying to use sudo to run "wall" command on a remote RedHat server. It seems that when using the setPty(true) the command executes ( we know this because we can see a line in the /var/log/messages that indicates that the command was preocessed ) but the message is not sent to any open console. When omitting the setPty(true) line from the code the command executes and the message is sent to all open consoles. In the code we setPty(true) because we need it for sudo execution. Below you can see a sample code which reproduces the issue. In this sample code we do not use sudo, but it illustrates the problem. Thanks, Gal Gafni Chen. import javax.swing.JOptionPane; import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import com.jcraft.jsch.UserInfo; public class testMsg { public static final String user = "root"; public static final String password = "rootPassword"; public static final String host = "192.168.1.17"; public static Session session = null; public static JSch jsch; public static void main(String[] args) { try { jsch = new JSch(); session = jsch.getSession(user,host,22); if (session != null) { session.setUserInfo(new myUserInfo()); session.connect(); session.setTimeout(300000); String command = "echo -e " + "\"test wall\\n\"| wall " ; Channel channel = session.openChannel("exec"); // ((ChannelExec) channel).setPty(true); ((ChannelExec) channel).setCommand(command); channel.connect(); channel.disconnect(); } session.disconnect(); } catch (JSchException e) { e.printStackTrace(); } } public static class myUserInfo implements UserInfo{ @Override public void showMessage(String message) { JOptionPane.showMessageDialog(null, message); } @Override public boolean promptYesNo(String arg0) { return true; } @Override public boolean promptPassword(String arg0) { return true; } @Override public boolean promptPassphrase(String arg0) { return true; } @Override public String getPassword() { return password; } @Override public String getPassphrase() { return null; } } } --
|
------------------------------------------------------------------------------ Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the endpoint security space. For insight on selecting the right partner to tackle endpoint security challenges, access the full report. http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________ JSch-users mailing list JSch-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jsch-users