
LastPass CLI ユーティリティを使用してパスワードを自動入力するシェル + expect スクリプトを作成したいと考えています。expectスクリプトのパスワード入力にlpass
返されたパスワードを送信する方法がわかりません。lpass
これまでの expect スクリプトは次のようになります。
# The beginning isn't important
expect -exact "\r
Please enter your username and password.\r
Username:"
send -- "my-username\r"
expect -exact "my-username\r
Password:"
send -- $(lpass show --password service\ im\ connecting\ to)
expect -exact "\r
# The rest of the expect script follows
$(...) 内の部分を実際にどのように記述すればよいのかわかりません...
答え1
exec
スクリプト内で関数を使用してシェルexpect
と同じ動作を実現したい$(...)
以下の例を参照してください。スクリプトなしでフィードする以下の
外部プログラムを使用します。4expect.sh
expect
#!/bin/sh
# Test program : let set filename as "4expect.sh"
# in the same directory where expect script will work
echo; read -p 'question: ' answer
echo "Got answer:>${answer}<"
ここでは、expect
外部プログラムからの「質問」を待機し、現在のディレクトリにある合計ファイル(外部プログラムの出力を取得しls
、 )をによってegrep
使用されるスクリプトを示します。expect
send
#!/usr/bin/expect -f
spawn -noecho ./4expect.sh
expect -re "question" { send -- [exec ls -la . | egrep "^total" ]\r }
interact
puts "\nDone.\n"
exit