Expect - Simulating ssh login

Clean #! /usr/bin/env expect set host [lindex $argv 0]; set user [lindex $argv 1]; set passwd [lindex $argv 2]; set timeout 5 spawn ssh $user@$host expect { "yes/no" { send "yes\r" exp_continue } "password:" { send "$passwd\r" exp_continue } "$user@$host:~? " { exit 0 } timeout { exit 2 } } exit 1 Wrapped inside bash #! /usr/bin/env bash assert_ssh_login() { local host="${1}" local user="${2}" local passwd="${3}" local details="$(echo -e "\ set timeout 5 \n\ spawn ssh ${user}@${host} \n\ expect { \n\ \"yes/no\" { \n\ send \"yes\r\" \n\ exp_continue \n\ } \n\ \n\ \"password:\" { \n\ send \"${passwd}\r\" \n\ exp_continue \n\ } \n\ \n\ \"${user}@${host}:~?...

October 20, 2015  |