使用带有expect语句的sftp UNIX bash脚本发送不完整的文件

时间:2013-02-25 15:05:03

标签: bash unix copy solaris sftp

这是一个需要在Solaris上运行的bash脚本,它将文件从dirlocal,copy复制到backupdir并通过SFTP发送。问题是它发送了4-5MB的数据,然后它挂起(我觉得在某个地方),而手动一切正常。不知道该怎么做......

#!/bin/bash
export LD_LIBRARY_PATH=".:../tool/bin:$LD_LIBRARY_PATH"
dirlocal=</export/home/somedir>
dirlocal_backup=</export/home/somebackupdir>
filename=*
if [ ! -e ${dirlocal}/${filename} ]; then
exit
fi
hostname=<some_ip_address>
username=ftp
password=FTP
remotedir=<somedir>
cd ${dirlocal}
cp * ${dirlocal_backup}
../tool/bin/expect -f - <<EOFEXPECT1 

set timeout 10
spawn -nottycopy -nottyinit sftp ${username}@${hostname}
expect {
     (yes/no) {send yes\r ; exp_continue }
     "*assword" {send ${password}\r ; exp_continue }
    }

expect -timeout 10 sftp { }
send "cd ${remotedir}\r";
expect -timeout 10 sftp { }
send "mput ${filename}\r";
expect -timeout -1 sftp {send "bye\r" }

#send "exit\r"
expect eof
EOFEXPECT1
if [ $? -eq 0 ]
then
rm ${filename} > /dev/null 2>&1
else
echo "something"
fi

1 个答案:

答案 0 :(得分:0)

由于对mark a comment as an answer的功能请求仍然被拒绝,我在此处复制上述解决方案。

最后让它发挥作用。编辑期望陈述是线索。感谢帮助!来自俄罗斯的问候! - user2107698