expectによる自動化

expectによる入力の自動化

次のようなファイルを作っておいて、./ssh.exp 192.168.251.154 などとやるとパスワードを自動入力してssh接続が可能。

#!/usr/bin/expect

set RemoteHost [lindex $argv 0]
set PW "programming"
#set PW [lindex $argv 1]
set Prompt "\[#$%>\]"

set timeout 5

spawn env LANG=C /usr/bin/ssh -o StrictHostKeyChecking=no -l training ${RemoteHost}
expect {
    -glob "(yes/no)?" {
        send "yes\n"
        exp_continue
    }
    -glob "password:" {
        send -- "${PW}\n"
    }
}

expect {
    -glob "${Prompt}" {
        interact
        exit 0
    }
}

https://qiita.com/ine1127/items/cd6bc91174635016db9b

  • expectによる自動化.1600228394.txt.gz
  • 最終更新: 2020/09/16 03:53
  • by 118.240.79.152