0

这是我的脚本

#!/bin/ksh
RemoteFile=`grep "${File}" ${TempLog}` --> the value of the variable is Site Information_2013-07-04-00-01-26.CSV

/usr/bin/expect << EOF
spawn sftp user@server
expect "password:"
send "123fakepassword\n"
expect "sftp>"
send "cd /home/user/pickup_dir\n"
expect "sftp>"
send "lcd /home/user/Scripts/mart/wmt/RAMDISK0\n"
expect "sftp>"
send "get $RemoteFile\n" ---> I'm  trying to pass it here so I can download the file. 
expect "sftp>"
send "exit\r"
EOF

但没有运气!,我怎样才能传递一个带双引号的文件名,所以它会执行为 (get "Site Information_2013-07-04-00-01-26.CSV\n") 我把它放在变量中导致文件名更改日期。还是我做错了?我知道硬编码密码不好,但我们不能使用 ssh-key 来拥有无密码的 sftp。谢谢!

4

2 回答 2

0

你只需要发送一些报价。选择一个

send "get '$RemoteFile'\n"
send "get \"$RemoteFile\"\n"
于 2013-07-04T12:06:38.617 回答
0
#!/bin/bash

while true
do

/usr/bin/expect <<EOF
set timeout 300
spawn sftp $remoteUser@$remoteIp
expect "yes/no" { 
    send "yes\r"
    expect "*?assword" { send "$remotePass\r" }
    } "*?assword" { send "$remotePass\r" }
expect "sftp> " { send "cd $RemoteFolderPath\r" }
expect "sftp> " { send "mget $remoteFileName\r" }
expect "sftp> " { send "quit\r" }
interact
EOF

done

exit
于 2015-09-10T05:45:47.847 回答