The Karaf* terminal allows some scripting of commands at the prompt. Eg:
($.context bundles) | grep -i felix
I have seen threads that discuss running multi-line scripts, presumably contained in a file.
My question is simply: How does one run a karaf language script file from the terminal? For my application the script can be a local file.
Thanks Very Much
*: JBoss Fuse (6.1.0.rehat-379)
You can use the shell:source
command like this:
Here is a sample script.
computer:karaf donald$ cat test.script
bundle:list -t 0 | head
echo 'Hello world 1'
echo 'Hello world 2'
echo 'Hello world 3'
Here is how you would invoke it from karaf:
Cobalt:bin donald$ ./karaf
__ __ ____
/ //_/____ __________ _/ __/
/ ,< / __ `/ ___/ __ `/ /_
/ /| |/ /_/ / / / /_/ / __/
/_/ |_|\__,_/_/ \__,_/_/
Apache Karaf (3.0.2)
Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown Karaf.
karaf@root()> shell:exec pwd
/Users/donald/apache-karaf-3.0.2
karaf@root()> shell:exec ls
LICENSE
NOTICE
README
RELEASE-NOTES
bin
data
demos
deploy
etc
instances
lib
lock
system
test.script
karaf@root()> shell:source test.script
START LEVEL 100 , List Threshold: 0
ID | State | Lvl | Version | Name
-----------------------------------------------------------------------------------------------------------
0 | Active | 0 | 4.2.1 | System Bundle
1 | Active | 5 | 2.2.0 | OPS4J Pax Url - aether:
2 | Active | 5 | 2.2.0 | OPS4J Pax Url - wrap:
3 | Active | 8 | 1.7.4 | OPS4J Pax Logging - API
4 | Active | 8 | 1.7.4 | OPS4J Pax Logging - Service
5 | Active | 10 | 3.0.2 | Apache Karaf :: Service :: Guard
6 | Active | 10 | 1.8.0 | Apache Felix Configuration Admin Service
Hello world 1
Hello world 2
Hello world 3
karaf@root()>