如何将 username/password 传递给 ambari-server sync-ldap 命令
How to pass username/password into ambari-server sync-ldap command
我正在尝试 运行 使用同步 ldap 命令的剧本:
ambari-server sync-ldap --all
事情是,执行命令后,它要求输入用户名和密码。
是否可以从 echo
或使用脚本 shell 自动传递用户名和密码,而无需手动传递?
试试下面的脚本
# 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
查看 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
命令。
我正在尝试 运行 使用同步 ldap 命令的剧本:
ambari-server sync-ldap --all
事情是,执行命令后,它要求输入用户名和密码。
是否可以从 echo
或使用脚本 shell 自动传递用户名和密码,而无需手动传递?
试试下面的脚本
# 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
查看 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
命令。