#!/bin/sh expect -c ' set timeout 10 spawn ssh localhost; expect { "Are you sure you want to continue connecting (yes/no)?" { send "yes\r"; exp_continue;} "password:" { send "YOURPASSWORD\r" expect "#" ; send "ls -al \r" expect "#" ; send "exit \r" } } interact '