如何将用户名/密码传递到ambari服务器syncldap命令

k5hmc34c  于 2021-05-27  发布在  Hadoop
关注(0)|答案(2)|浏览(366)

我正在尝试使用sync ldap命令运行剧本: ambari-server sync-ldap --all 问题是,在执行命令之后,它要求输入用户名,然后输入密码。
是否有自动传递用户名和密码的方法 echo 或者使用脚本shell,而不必手动传递它?

nfg76nw0

nfg76nw01#

尝试使用下面的脚本


# cat /tmp/ambari-server-sync-ldap-unattended.sh

# !/usr/bin/expect

set timeout 20
spawn /usr/sbin/ambari-server sync-ldap --groups=/etc/ambari-server/ambari-groups.csv
expect "Enter Ambari Admin login:" { send "admin\n" }
expect "Enter Ambari Admin password:" { send "notTheRealPasswordOfCourse\n" }
interact
h6my8fg2

h6my8fg22#

查看expect。
一个简单的例子是使用下面的脚本。


# !/usr/bin/expect -f

ambari-server sync-ldap --all

# wait until the prompt shows "enter username". Change this to adapt to your application.

expect "enter username"
send "your_username\r"

# wait until the prompt shows "password: ". Change this to adapt to your application.

expect "password: "
send "yourPAssWoRD\r"

interact

免责声明:我从未使用过 ambari-server 之前的命令。

相关问题