0

我正在尝试在 bash 脚本中使用 expect 来提供 SFTP 密码并放置其他命令。我正在尝试获取二进制 SFTP 的返回码。

我的测试脚本:

#!/bin/bash

USER=$1
HOST=$2
PASSWD=$3
PORT=$4
FILEIN=$5
FILEOUT=$6
ACTION=$7

CR_FTP=`/usr/bin/expect <<EOF | tee -a log.log
spawn sftp -v -oPort=$PORT $USER@$HOST
expect "password:"
send "$PASSWD\r"
expect "sftp>"
send "ls\r"
expect "sftp>"
send "$ACTION $FILEIN $FILEOUT\r"
expect "sftp>"
send "bye\r"
EOF`

echo " -------------------- $CR_FTP --------------------------"
4

1 回答 1

0
...
send "bye\r"
expect eof
set details [wait]
puts "sftp exit status=[lindex $details 3]"
EOF`

See http://www.tcl.tk/man/expect5.31/expect.1.html

于 2012-04-05T16:33:44.267 回答