Expect

For ssh, in a sh script:

#!/bin/sh
expect -c "
spawn ssh localhost
expect \"Are you sure you want to continue connecting (yes/no)? \"
send \"yes\r\"
interact
"