简体   繁体   English

通过 bash 脚本登录到 karaf 控制台

[英]Login to karaf console via bash script

What I'm trying to do is to login to karaf console via bash script and execute there some commands.我想要做的是通过 bash 脚本登录到 karaf 控制台并在那里执行一些命令。 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.然后,当我输入密码时,karaf 正在打开,当我关闭它时,脚本的其余部分正在执行。 Is there a way to type a password automaticly and execute commands inside?有没有办法自动输入密码并在里面执行命令?

You should try apache karaf client.您应该尝试 apache karaf 客户端。 See the example below.请参阅下面的示例。

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

Output输出

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

Apache Karaf (4.2.8)阿帕奇卡拉夫 (4.2.8)

Hit '' for a list of available commands and '[cmd] --help' for help on a specific command.点击 '' 获取可用命令列表,点击 '[cmd] --help' 获取特定命令的帮助。 Hit 'system:shutdown' to shutdown Karaf.点击“system:shutdown”来关闭 Karaf。 Hit '' or type 'logout' to disconnect shell from current session.点击 '' 或输入 'logout' 以断开 shell 与当前会话的连接。

karaf@root()> log:clear karaf@root()> 日志:清除

karaf@root()> karaf@root()>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM