SSHサンプル
シェルで実行
#!/bin/sh pass="password" result=`expect -c " set timeout 5 log_user 0 spawn ssh localhost expect yes/no { send \"yes\n\" expect password send \"${pass}\n\" puts firstlogin } password { send \"${pass}\n\" puts manylogin } expect \"#\" send \"touch test\n\" expect \"#\" exit 0 "` echo logintime : $result
expectで実行
#!/usr/bin/expect set timeout 5 log_file -noappend expect.log spawn ssh localhost expect "\\$" send "uname -a\n" expect "\\$" send "date\r" expect "\\$"
SFTPサンプル
expectで実行
#!/usr/bin/expect
set timeout 10
spawn sftp -P 12345 username@example.com
expect "password"
send "PassWord\r"
expect ">"
send "get test.txt\r"
expect ">"
send "quit\r"
expect ">"