这是一个需要在 Solaris 上运行的 bash 脚本,它从 dirlocal 获取文件,复制到 backupdir 并通过 SFTP 发送它们。问题是它只发送 4-5MB 的数据,然后它挂起(我认为在 mput 的某个地方),而手动一切正常。真的不知道该怎么办...
#!/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