6

I started Apache Karaf 3.0.0 in server mode using $KARAF_HOME/bin/start in CentOS 6.5. Then I wanted to run several commands using $KARAF_HOME/bin/client and also capture the output of these commands, so as to make sure the commands ran successfully. The output did get spit out on my console but I was never able to redirect it into a file. Seems like Karaf doesn't write anything to the output stream or error stream. I tried the following:

[apache-karaf-3.0.0]$ ./bin/start clean
[apache-karaf-3.0.0]$ ./bin/client "bundle:list"
Logging in as karaf
282 [pool-2-thread-3] WARN org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier - Server at /0.0.0.0:8101 presented unverified key:
START LEVEL 100 , List Threshold: 50
 ID | State  | Lvl | Version                 | Name
------------------------------------------------------------------------------------
 91 | Active |  80 | 1.8.0                   | Commons Codec
 92 | Active |  80 | 2.6                     | Commons Lang
 93 | Active |  80 | 15.0.0                  | Guava: Google Core Libraries for Java

[apache-karaf-3.0.0]$ ./bin/client "bundle:list" >& bundleList
[apache-karaf-3.0.0]$ cat bundleList
null

Nothing got written to the file bundleList. Piping the output doesn't seem to help either.

Donald_W
  • 1,773
  • 21
  • 35
The Governor
  • 1,152
  • 1
  • 12
  • 28
  • `bin\client` is an script. here the source code of 3.0.0 version: https://github.com/apache/karaf/blob/karaf-3.0.0/assemblies/features/framework/src/main/filtered-resources/resources/bin/client. I don't know if it affects... – logoff Apr 12 '15 at 09:35

3 Answers3

4

To make Aviv's solution work, simply use a pipe, e.g. "bundle:list | tac -f /tmp/yourfile"

Frizz
  • 2,524
  • 6
  • 31
  • 45
  • The opendaylight version 4.1.5 does not support `-f` option for the `shell:tac` command, but `-a`. See `help shell:tac` `-a --append append to FILE`. – kwarnke Aug 06 '18 at 11:40
3

I'm able to capture client output in Karaf version 3.0.2 .

user@hostname:~$ client bundle:list > bundleinfo.txt

This results in following debug info on the console:

2053 [sshd-SshClient[36c8e545]-nio2-thread-2] WARN org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier - Server at [/0.0.0.0:8101, DSA, xx:xx:xx:xx:xx:xx:xx:c 2:3a:5a:9b:87:ed:e0:b2:6a] presented unverified {} key: {}

..and of course the bundleinfo.txt file with content as expected:

user@hostname:~$ head -5 bundleinfo.txt
START LEVEL 100 , List Threshold: 50
 ID | State    | Lvl | Version                 | Name
---------------------------------------------------------------------------------------------
38 | Active   |  80 | 3.2.5.RELEASE           | Spring Security Core
39 | Active   |  80 | 1.0.0.1                 | Apache ServiceMix :: Bundles :: javax.inject
RRM
  • 2,495
  • 29
  • 46
3

For command line, I use "tac" and redirect to a file with -f , in Karaf 3.0.3, try it or learn what it does with --help

Aviv
  • 59
  • 4
  • If this is really an answer to the question, you should improve it, explain it: http://stackoverflow.com/help/how-to-answer – Soma May 04 '15 at 12:52
  • If you do not understand my answer, I can not really help you! – Aviv May 04 '15 at 12:59