0

私はシェルを期待してsftpをやろうとしていました。しかし、発生する可能性のあるさまざまな sftp エラー コードを取得できませんでした。代わりに、戻り値を 0 として取得していました

これがコードスニペットとopです

"${sftp_prompt}" {

send "${command}\r"
    expect "${sftp_prompt}"

    # Close the sftp session
    send "bye\r"

expect eof

set details [wait]

puts "sftp exit status=[lindex $details 3]"

   }

}

出力:

spawn sftp root@dsc-A

Connecting to dsc-A...

root@dsc-a's password:

sftp> get shiv.txt /var/log/nsn/pkiclient/Response_files/

Couldn't stat remote file: No such file or directory

File "/root/shiv.txt" not found.

sftp> bye

sftp exit status=0

SSH_ERROR_OK | Indicates successful completion of the operation

Desired op : 終了ステータスが 10 になることを期待しています。

sftp エラー - SSH_ERROR_NO_SUCH_PATH | ファイル パスが存在しないか、無効です。

誰でも助けることができますか?

4

1 に答える 1

0

sftp セッションは正常に終了するため、結果コード 0 が返されます。expect ブロックで sftp エラーをトラップする必要があります。

set timeout 60
send "$command\r"
expect {
    timeout {
        puts "A timeout occured"
        exit 1 
    }

    #One of many errors 
    -re "Couldn't|Can't" {
        puts "Can not perform $command"
        exit 2 
    } 

    #Ok 
    "sftp>" {
        puts "$command completed successfully"
    }
}
于 2014-01-21T20:20:28.287 に答える