Here is my sample expect script, that reporting the above error. Please take a look and let me know if any issue with this. I'm suspecting issue with expect_before block. Is there any limit to expect_before block? Also, one strange thing noticed is when I added pipe '|' after string like "Connection Refused"| it is working fine though it is part of trial and error.
#!/usr/bin/expect
spawn sftp {sample_hostname}
set timeout 30
gets stdin password
expect_before {
"(yes/no)" {
send "yes
"
exp_continue
}
"Connection Refused" {
exit 1 }
"not found." {
exit 2 }
"Permission denied" {
exit 3 }
" Could not resolve hostname" {
exit 4 }
"REMOTE HOST IDENTIFICATION HAS
CHANGED" {
exit 5 }
"closed by remote host." {
exit 6 }
"Broken pipe" {
exit 7 }
}
expect {
"assword:" {
send "$password
" }
timeout {
exit 7 }
}
set timeout 3600
expect_before {
"assword:" {
exit 6 }
"Connection Refused" {
exit 1 }
"not found." {
exit 2 }
"Permission denied" {
exit 3 }
"Broken pipe" {
exit 4 }
closed by remote host." {
exit 5 }
}
expect {
"sftp>" { }
timeout { exit 7 }
}
send "ls -l /sample_directory/
"
expect "sftp>"
send "bye
"