0

What I'm trying to do is to login to karaf console via bash script and execute there some commands. I'm trying to do it like this:

#!/bin/bash
cmd='sudo ssh -p 8101 openhab@localhost'
eval $cmd
cmd='echo "password" && echo log:clear && echo logout'
eval $cmd

How can you suspect, it doesn't work and it's freezing at "Password: ", waiting for user to type. Then, when I type the password, karaf is opening and when I close it, the rest of script is executing. Is there a way to type a password automaticly and execute commands inside?

Jbro
  • 1
  • To give you a great answer, it might help us if you have a glance at [ask] if you haven't already. It might be also useful if you could provide a [mcve]. – Mat Mar 09 '20 at 08:40
  • Does this answer your question? [Automatically enter SSH password with script](https://stackoverflow.com/questions/12202587/automatically-enter-ssh-password-with-script) – bob dylan Mar 09 '20 at 08:41
  • 1
    Hi and welcome. Maybe you want to have a look at expect, a language built to automate interactions https://likegeeks.com/expect-command/ – Francesco Gasparetto Mar 09 '20 at 09:07

1 Answers1

2

You should try apache karaf client. See the example below.

 echo "log:clear" | /opt/apache-karaf-4.2.8/bin/client

Output

    __ __                  ____      
   / //_/____ __________ _/ __/      
  / ,<  / __ `/ ___/ __ `/ /_        
 / /| |/ /_/ / /  / /_/ / __/        
/_/ |_|\__,_/_/   \__,_/_/         

Apache Karaf (4.2.8)

Hit '' for a list of available commands and '[cmd] --help' for help on a specific command. Hit 'system:shutdown' to shutdown Karaf. Hit '' or type 'logout' to disconnect shell from current session.

karaf@root()> log:clear

karaf@root()>