Hi Paul,

also calls without specifying the bash like [./bin/client -v -h localhost -a 
8101 -u karaf -p karaf \"bundle:list > /tmp/bundleinfo.txt\"] give no result. 
The interesting thing is that I see in the Karaf log that there is an 
authentication on the SSH server. Here is an excerpt from the Karaf log:
2023-01-13T10:31:42,762 | INFO  | 
sshd-SshServer[6058e7bb](port=8101)-nio2-thread-1 | ServerSessionImpl           
     | 254 - org.apache.sshd.osgi - 2.5.1 | Session admin@/127.0.0.1:40412 
authenticated
2023-01-13T11:01:44,449 | INFO  | 
sshd-SshServer[6058e7bb](port=8101)-timer-thread-1 | ServerSessionImpl          
      | 254 - org.apache.sshd.osgi - 2.5.1 | 
Disconnecting(ServerSessionImpl[admin@/127.0.0.1:40412]): 
SSH2_DISCONNECT_PROTOCOL_ERROR - Detected IdleTimeout after 1800984/1800000 ms.

But apparently the command I passed is not processed. It should write a list of 
bundles to disk, but it does not.

Also with the following command [./bin/client -v -h localhost -a 8101 -u karaf 
-p karaf \"bundle:list | shell:tac -a /tmp/bundleinfo.txt\"] the result should 
be redirected to a file, but it does not.

I'll keep looking...

Von: Paul McCulloch [mailto:pkmccull...@gmail.com]
Gesendet: Freitag, 13. Januar 2023 12:30
An: user@karaf.apache.org
Betreff: Re: Verify SSH client login with Java

Digging out some code I have that does call the client in the way you do, the 
most obvious difference is that I just call "client" and rely on something in 
the runtime to launch an appropriate shell to execute it. My suspicion is that 
you are getting nested shells and the command line arguments aren't being 
passed as you expect.
I run client or client.bat in this way (OS dependent) and in both cases i just 
exec the shell script without any explicit bash/sh/cmd.exe mentioned.

If that doesn't help I'd try logging stderr as well as stdout & see what that 
says.

On Fri, 13 Jan 2023 at 10:43, Domke, Alexander 
<a.do...@cenit.com<mailto:a.do...@cenit.com>> wrote:
Hello Paul and Łukasz! Thank you for your answers.

I can already see that the client was found and called, as I get the "client: 
Ignoring predefined value for KARAF_HOME" message. However, it would be better 
to get the result of the commands passed to the client.

Maybe someone has more ideas?

-----Ursprüngliche Nachricht-----
Von: Łukasz Dywicki [mailto:l...@code-house.org<mailto:l...@code-house.org>]
Gesendet: Donnerstag, 12. Januar 2023 20:34
An: user@karaf.apache.org<mailto:user@karaf.apache.org>
Betreff: Re: Verify SSH client login with Java

Pay attention to directory in whcih your main() is being ran. For start try 
setting absolute path to bin/client.

Best,
Łukasz

On 12.01.2023 16:29, Domke, Alexander wrote:
> Hello all,
>
> I'm trying to use a Java program to check if the Karaf SSH client that
> comes with the program is working. For this I wrote a simple Java
> program, but the client does not return the result.  When I run the
> command "bash -c ./bin/client -u karaf -p karaf \"system:version\""
> manually in the console it works, but not when I run it through the
> program.
>
> import java.io.BufferedReader;
>
> import java.io.IOException;
>
> import java.io.InputStreamReader;
>
> public class App {
>
>      public static void main(String[] args) throws Exception {
>
>          System.out.println("SSH Client Check");
>
>          testSSHClient();
>
>      }
>
>      public static void testSSHClient() throws Exception {
>
>          String commandUnix = "bash -c ./bin/client -u karaf -p karaf
> \"system:version\"";
>
>          String clientLoginResult = executeSSHClient(commandUnix);
>
>          System.out.println(clientLoginResult);
>
>      }
>
>      private static String executeSSHClient(String command)
>
>              throws IOException, InterruptedException {
>
>          StringBuffer output = new StringBuffer();
>
>          Process p = Runtime.getRuntime().exec(command);
>
>          p.waitFor();
>
>          BufferedReader reader = new BufferedReader(new
> InputStreamReader(p.getInputStream()));
>
>          String line = "";
>
>          while ((line = reader.readLine()) != null) {
>
>              output.append(line + "\n");
>
>          }
>
>          String result = output.toString();
>
>          return result.trim();
>
>      }
>
> }
>
> Does anyone have any idea what could be the reason for this?
>
> Regards
>
> Alex
>
>
> CENIT AG, Industriestrasse 52-54, 70565 Stuttgart, Tel.: +49 711
> 7825-30, Fax: +49 711 7825-4000, Internet: www.cenit.com<http://www.cenit.com>
> Geschaeftsstellen (Branch Offices): Berlin, Frankfurt, Hamburg,
> Hannover, Muenchen, Oelsnitz, Ratingen, Saarbruecken
> Vorstandsmitglieder (Members of the Board): Peter Schneck, Axelle Maze
> Aufsichtsratsmitglieder (Supervisory Board Members): Rainer Koppitz
> (Vorsitzender des Aufsichtsrats / Chairman of the Supervisory Board),
> Prof. Dr. Isabell Welpe, Ricardo Malta Bankverbindungen (Bank
> Accounts):
> Deutsche Bank (BLZ 600 700 70) Kto. 1661 040 IBAN : DE85 6007 0070
> 0166
> 1040 00 SWIFT-CODE : DEUTDESS,
> Commerzbank (BLZ 600 400 71) Kto. 532 015 500 IBAN : DE83 6004 0071
> 0532
> 0155 00 SWIFT-Code : COBADEFF600,
> Registergericht (Registry court): Amtsgericht Stuttgart
> Handelsregister (Commercial Register): HRB Nr. 19117 Umsatzsteuer
> (VAT) ID: DE 147 862 777

CENIT AG, Industriestrasse 52-54, 70565 Stuttgart, Tel.: +49 711 7825-30, Fax: 
+49 711 7825-4000, Internet: www.cenit.com<http://www.cenit.com>
Geschaeftsstellen (Branch Offices): Berlin, Frankfurt, Hamburg, Hannover, 
Muenchen, Oelsnitz, Ratingen, Saarbruecken
Vorstandsmitglieder (Members of the Board): Peter Schneck, Axelle Maze
Aufsichtsratsmitglieder (Supervisory Board Members): Rainer Koppitz 
(Vorsitzender des Aufsichtsrats / Chairman of the Supervisory Board), Prof. Dr. 
Isabell Welpe, Ricardo Malta
Bankverbindungen (Bank Accounts):
Deutsche Bank (BLZ 600 700 70) Kto. 1661 040 IBAN : DE85 6007 0070 0166 1040 00 
SWIFT-CODE : DEUTDESS,
Commerzbank (BLZ 600 400 71) Kto. 532 015 500 IBAN : DE83 6004 0071 0532 0155 
00 SWIFT-Code : COBADEFF600,
Registergericht (Registry court): Amtsgericht Stuttgart
Handelsregister (Commercial Register): HRB Nr. 19117
Umsatzsteuer (VAT) ID: DE 147 862 777

CENIT AG, Industriestrasse 52-54, 70565 Stuttgart, Tel.: +49 711 7825-30, Fax: 
+49 711 7825-4000, Internet: www.cenit.com
Geschaeftsstellen (Branch Offices): Berlin, Frankfurt, Hamburg, Hannover, 
Muenchen, Oelsnitz, Ratingen, Saarbruecken
Vorstandsmitglieder (Members of the Board): Peter Schneck, Axelle Maze
Aufsichtsratsmitglieder (Supervisory Board Members): Rainer Koppitz 
(Vorsitzender des Aufsichtsrats / Chairman of the Supervisory Board), Prof. Dr. 
Isabell Welpe, Ricardo Malta
Bankverbindungen (Bank Accounts):
Deutsche Bank (BLZ 600 700 70) Kto. 1661 040 IBAN : DE85 6007 0070 0166 1040 00 
SWIFT-CODE : DEUTDESS,
Commerzbank (BLZ 600 400 71) Kto. 532 015 500 IBAN : DE83 6004 0071 0532 0155 
00 SWIFT-Code : COBADEFF600,
Registergericht (Registry court): Amtsgericht Stuttgart
Handelsregister (Commercial Register): HRB Nr. 19117
Umsatzsteuer (VAT) ID: DE 147 862 777

Reply via email to