- 利用 Expect 套件,寫出自動回應系統訊息的程式。
- 安裝 Expect 套件
# yum install expect
- 寫個自動登入的 Expect Scripts 程式
# vim login.sh #!/usr/bin/expect -f spawn ssh -i .ssh/id_rsa demo@helloworld expect { "yes/no" { send "yes\r" expect "passphrase" send "123456\r" } "passphrase" { send "123456\r" } } interact timeout 1 { send "logout\n" } exit
- 執行測試
#chmod +x login.sh # ./login.sh
參考文獻:
- http://blog.xuite.net/m740138.m740138/blog/25445084-%E5%B0%8D%E8%A9%B1%E5%9E%8B%E8%87%AA%E5%8B%95%E5%9B%9E%E6%87%89%E8%85%B3%E6%9C%AC(%E4%BD%BF%E7%94%A8expect)
- http://wiki.tcl.tk/11583
- https://blog.longwin.com.tw/2011/07/expect-shell-auto-linux-2011/
- http://white-co.blogspot.tw/2012/01/expect-spawnlinux-expect.html