Little
September 19, 2013, 1:04am
1
hi,
how can i know whether a command inside an sftp script has failed or not?
i have a sftp expect script
#!/usr/bin/expect
spawn /usr/bin/sftp abc@ftp.abc.com
expect "sftp>"
send "cd dir\r"
expect "sftp>"
send "mput abc.txt\r"
expect "sftp>"
send "mput def.xls\r"
expect "sftp>"
send "bye\r"
expect eof
suppose there is no directory named "dir" in sftp remote server, then the command at line 4 i.e. cd dir
will fail and the script should not proceed further.
how can i do this?
expect {
"550 dir: No such file or directory" {send "quit\n" ; exit }
"250 CWD command successful" {exp_continue}
}
Little
September 19, 2013, 4:20am
3
where should i add this code block? and how it works??
Right after the
send "cd dir\r"
You probably have to adjust the "550 .." and "250 CWD..." to your servers response as well.
This works like case/switch. You could add even more "cases".
Little
September 24, 2013, 11:45am
5
I am not getting how to adjust the return codes. can you give me an example how to do that.. modify the above sample script given by me.
Not a trick question; simply change the text to match the exact text your sftp server sends when you do those commands manually...