Chad Kellerman | 6 Oct 22:07 2010
Picon

Capturing STDERR of remote command

Jsch User/Authors,
   I am writing a wrapper class around jsch that would make it easier
to implement ssh/scp connections.

So far I am able to connect thru ssh via private keys and issue a
command on a remote sure.
I am able to capture the output, but the stderr I am having issues
with.  When ever I start to work with STDERR I see:

INFO: Caught an exception, leaving main loop due to Socket Closed

whenever I turn on logging.

No matter where I tried to implement
((ChannelExec)channel).getErrStream();  that message shows up.

What is the proper way to gather stderr for the remote command?  Or is
the above message something that can be ignored.

My code:

public class SecureCommandUtility
{	
	
	static {
		// Don't check host key
		Properties config = new Properties();
		config.put("StrictHostKeyChecking", "no");
		config.put("Protocol", "2");
		config.put("Ciphers", "arcfour,arcfour128");
(Continue reading)

Baranski, Jack | 6 Oct 22:49 2010

Re: Capturing STDERR of remote command

Try getting this instead, it works for me:

channel.getExtInputStream();

Good luck,

Jacek

-----Original Message-----
From: Chad Kellerman [mailto:sunckell@...] 
Sent: Wednesday, October 06, 2010 3:07 PM
To: jsch-users@...
Subject: [JSch-users] Capturing STDERR of remote command

Jsch User/Authors,
   I am writing a wrapper class around jsch that would make it easier
to implement ssh/scp connections.

So far I am able to connect thru ssh via private keys and issue a
command on a remote sure.
I am able to capture the output, but the stderr I am having issues
with.  When ever I start to work with STDERR I see:

INFO: Caught an exception, leaving main loop due to Socket Closed

whenever I turn on logging.

No matter where I tried to implement
((ChannelExec)channel).getErrStream();  that message shows up.

(Continue reading)

Chad Kellerman | 7 Oct 13:20 2010
Picon

Re: Capturing STDERR of remote command

On Wed, Oct 6, 2010 at 4:49 PM, Baranski, Jack <Baranski@...> wrote:
> Try getting this instead, it works for me:
>
> channel.getExtInputStream();
>
> Good luck,
>
> Jacek

Thanks for the suggestion.  But here is the log info output when all
Error Stream code is commented:

INFO: Connecting to HOSTNAME port 22
INFO: Connection established
INFO: Remote version string: SSH-2.0-OpenSSH_5.2
INFO: Local version string: SSH-2.0-JSCH-0.1.42
INFO: CheckCiphers:
aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: aes256-ctr is not available.
INFO: aes192-ctr is not available.
INFO: aes256-cbc is not available.
INFO: aes192-cbc is not available.
INFO: arcfour256 is not available.
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server->client aes128-ctr hmac-md5 none
INFO: kex: client->server aes128-ctr hmac-md5 none
INFO: SSH_MSG_KEXDH_INIT sent
INFO: expecting SSH_MSG_KEXDH_REPLY
INFO: ssh_rsa_verify: signature true
(Continue reading)

Dan Churchill | 7 Oct 16:59 2010
Picon

Re: Capturing STDERR of remote command

  I'm no expert, but in my experience, channel.connect needs to be 
called after the I/O streams have been set up the way you want. Here is 
a method I wrote that separately collects stderr, stdout, and the exit 
code. I was unable to figure out how to interleave stderr and stdout 
into the same stream. This also doesn't try to display the stream as it 
comes in - it only extracts it from the buffered reader after after the 
remote command has finished execution:

     private ExecResults remoteExec(final String command, final 
InputStream in)
             throws MyException
     {
         logger.log(LogLevel.DEBUG, "doing remote execution: " + command);
         ExecResults results = new ExecResults();
         try {
             Channel c = sshSession.openChannel("exec");
             ((ChannelExec)c).setCommand(command);

             // Direct input to command
             c.setInputStream(in);

             // Direct stderr output of command
             InputStream err = ((ChannelExec)c).getErrStream();
             InputStreamReader errStrRdr = new InputStreamReader(err, 
"UTF8");
             Reader errStrBufRdr = new BufferedReader(errStrRdr);

             // Direct stdout output of command
             InputStream out = c.getInputStream();
             InputStreamReader outStrRdr = new InputStreamReader(out, 
(Continue reading)

Chad Kellerman | 7 Oct 19:18 2010
Picon

Re: Capturing STDERR of remote command

Thanks for the Code.  I see what you did there....

I think there might be an issue with the session.disconnect() call
when setting up the InputStream for stderr.

even with the code below if you turn on JSCH logging and perform a
sshSession.disconnect();  the exception will be created...

INFO: Caught an exception, leaving main loop due to Socket Closed

Thanks again.  Since what I am writing isn't anything that goes into a
container, I'll remove the session.disconnect().

BTW.  I like the way you handled the stdout and err streams....

Chad

On Thu, Oct 7, 2010 at 10:59 AM, Dan Churchill <dchurchi@...> wrote:
>  I'm no expert, but in my experience, channel.connect needs to be
> called after the I/O streams have been set up the way you want. Here is
> a method I wrote that separately collects stderr, stdout, and the exit
> code. I was unable to figure out how to interleave stderr and stdout
> into the same stream. This also doesn't try to display the stream as it
> comes in - it only extracts it from the buffered reader after after the
> remote command has finished execution:
>
>     private ExecResults remoteExec(final String command, final
> InputStream in)
>             throws MyException
>     {
(Continue reading)

cnu | 25 Oct 18:16 2011
Picon

Re: [ sshexec ] Caught an exception, leaving main loop due to socket closed

Hi, i am getting this exception when running a scp command on a remote host 
using sshexec in ANT. i am getting the build as successful but i am seeing 
this exception. can this exception be ignored or is there any work around to 
avoid this. Thank you

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning <at> Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
Paul Ebermann | 25 Oct 20:02 2011
Picon
Picon
Picon

Re: [ sshexec ] Caught an exception, leaving main loop due to socket closed

cnu schrieb:
> Hi, i am getting this exception when running a scp command on a remote host 
> using sshexec in ANT. i am getting the build as successful but i am seeing 
> this exception. can this exception be ignored or is there any work around to 
> avoid this.

Did your scp succeed? I.e. did your file arrive on the remote host (and
is identical with what you sent)?

I think this would be the main criteria to decide if you can ignore this.

Paŭlo

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning <at> Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
JSch-users mailing list
JSch-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users
Chad Kellerman | 25 Oct 20:32 2011
Picon

Re: [ sshexec ] Caught an exception, leaving main loop due to socket closed

I've seen this when the connection closes and you have the logger enabled.   I think it is printed when the connection is closed no matter what, successful or unsuccessful...
 

On Tue, Oct 25, 2011 at 2:02 PM, Paul Ebermann <Paul-Ebermann-Mmb7MZpHnFY@public.gmane.org> wrote:
cnu schrieb:
> Hi, i am getting this exception when running a scp command on a remote host
> using sshexec in ANT. i am getting the build as successful but i am seeing
> this exception. can this exception be ignored or is there any work around to
> avoid this.

Did your scp succeed? I.e. did your file arrive on the remote host (and
is identical with what you sent)?

I think this would be the main criteria to decide if you can ignore this.


Paŭlo

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning <at> Cisco Self-Assessment and learn
about Cisco certifications, training, and career opportunities.
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
JSch-users mailing list
JSch-users-5NWGOfrQmncRDUWM+popnw@public.gmane.orgforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users



--
A grasshopper walks into a bar and the bartender says "Hey, we have a drink named after you." And the grasshopper says "Really, You have a drink named Murray?"
------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning <at> Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
JSch-users mailing list
JSch-users@...
https://lists.sourceforge.net/lists/listinfo/jsch-users

Gmane