[英]How to pass Username and password to an application using shell script?
我想讓腳本登錄到應用程序,其流程就像
現在我的問題是我可以聯系到應用程序啟動,但是無法通過腳本提供用戶名和密碼。
cd cd /ld62_prod
drv
112233 #username
112233 #password
我做錯了。
沒有安全性:
您可以使用:
echo "User name: $0"
echo "Password: $1"
您可以使用$0
和$1
來使用特定值。
有關更多詳細信息,請參考Shell腳本 。
具有安全性:
read -s -p "Password: " password
在Linux(和cygwin)下,這種形式可以在bash和sh中使用。 但是,它可能不是標准的Unix sh。
有關更多信息和選項,請在bash中鍵入“幫助閱讀”。
$ help read
read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
Read a line from the standard input and split it into fields.
...
-p prompt output the string PROMPT without a trailing newline before
attempting to read
...
-s do not echo input coming from a terminal
您可以使用expect
,這是一個標准工具,可以與像您這樣的交互式程序/腳本進行通信。 它的手冊頁說:
Expect是根據腳本與其他交互式程序“對話”的程序。 在腳本之后,Expect知道程序可以期望什么,正確的響應應該是什么。 解釋語言提供分支和高級控制結構來引導對話。 此外,用戶可以根據需要進行控制並直接進行交互,然后將控制權返回給腳本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.