autossh & expect

Hah! Don't try this at home work, kids:

$ cat otp.txt 
123456
234567
345678

$ cat autossh.exp
#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set password [lindex $argv 1]
set command [lindex $argv 2]
set timeout 30
spawn ssh -L 1234:localhost:80 -N $ipaddress
expect {
        "yes/no"    { send "yes\r"; exp_continue }
        "password:" { send "$password\r" }
}
expect ""
# send "$command \r"
# send "exit\r"
 
expect eof
exit

$ cat otp.txt | while read p; do ./autossh.exp bob@ssh.example.com $p; done
Yes, public key authentication would be the way to go. But when used in combination with a (known) one-time password list, the above does the trick. No, I'm not actually using this and neither should you!