expect 真是一個好東西,可以解決免密登錄服務器和免密下載的問題。
記錄一下。
免密登錄:from here
mac 安裝brew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install mac安裝expect(需要先安裝brew,沒有安裝的話看上邊) brew install expect mac一鍵登錄服務器腳本 set user "username" set host "123.126.88.**" set password "yourpassword" set timeout -1 spawn ssh $user@$host expect "*assword:*" send "$password\r" interact # expect eof
另一個例子是這里:
[root@localhost ~]# vim auto_login.sh #!/usr/bin/expect spawn ssh root@192.168.43.143 expect { “(yes/no)” {send “yes\r”; exp_continue} “*password” {send “123123\r”} } interact
免密拷貝:
cat /opt/shell/expect_scp.sh #!/bin/bash ip="10.168.1.202" user="root" expect << EOF set timeout -1 spawn bash -c “scp -pr /home/* $user@$ip:/home/” expect { “yes/no” {send “yes\r”;exp_continue} “password” {send_user "come here"; send “123456\r”;} } expect eof exit EOF
浙公網安備 33010602011771號