0
通過SFTP得到的文件名下面是我的腳本我如何傳遞一個文件名以空間,因此可以在預期
#!/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 [email protected]
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
,但沒有運氣!我如何傳遞一個文件名用雙引號,因此它會執行爲(獲得「網站信息_2013-07-04-00-01-26.CSV \ n」)我把它放在變量導致文件名更改日期。或者我是否做錯了?我知道硬編碼密碼不好,但我們不能使用ssh-key來獲得無密碼的sftp。謝謝!
我格倫感謝我的單引號做了答覆,我得到下面的錯誤之一: SFTP>獲得「網站Information_2013-07-04-00-01-26.CSV 」 未結束的報價參數 的雙引號: SFTP>特寫報價 在執行 後多餘的字符「\ n」 d「得到‘網站Information_2013-07-04-00-01-26.CSV ’ 我試着也可以將它置於期望變量集文件\「$ RemoteFile \」或設置文件$ RemoteFile並稱之爲sti我無法下載文件 – turf
我做了一個解決方法使用sed: File = $(echo「$ RemoteFile」| sed's/^/\\「/; s/$/\\」/'| sed's/^ M //') 然後在我的腳本中調用它 發送「get $ File \ n」 – turf
更好的解決方案是從$ TempLog中刪除便攜式返回 - 'dos2unix「$ TempLog」 '或'sed -i's/\ r $ //'「$ TempLog」' - 在分配RemoteFile變量之前執行此操作。 –