expectコマンド - tetsuyaf1100/hello-world GitHub Wiki

ssh自動化expectサンプル

  • ssh.exp
#!/usr/bin/expect

log_file ./expect.log

set USER_NAME "user"
set SREVER_NAME "server_ame"
set PW "password"

set timeout 5

spawn env LANG=C /usr/bin/ssh ${USER_NAME}@${SERVER_NAME}

expect {
    "(yes/no)?" {
        send "yes\n"
        exp_continue
    }
    "password:" {
        send "${PW}\n"
    }
}

expect {
    "\[#$%>\]" {
        exit 0
    }
}
  • usage
chmod 755 ssh.exp
./ssh.exp