0
我想寫一個shell腳本,從文本文件中獲取一組參數,然後根據這些參數執行SFTP。基本上,我正在採取每日webstats日誌,並將其移動到中央位置。分配變量導致SFTP失敗
我遇到的問題是SFTP基於我分配變量的方式失敗。我已調試並發現while循環通過回顯變量循環正常工作。我得到的錯誤是連接關閉。
#!/bin/sh
source /home/ntadmin/webstats/bin/webstats.profile
source /home/ntadmin/webstats/bin/webstats.blogs.profile
DATE=`date +%m%d%Y`
SOURCE_FILE="`echo $WS_BC_SOURCE_FILE | sed -e 's/mmddyyyy/'$DATE'/'`"
IFS=","
while read WS_BLOG_NAME WS_BLOG_SOURCE_VAR WS_BLOG_DEST_VAR WS_BC_SERVER1;
do
#Step 1 SFTP
cd $PERL_DIR
if $PERL_DIR/sftp.pl $WS_BC_SERVER1 $WS_BC_ID $WS_BC_PW $WS_BLOG_SOURCE_VAR/$SOURCE_FILE $WS_BLOG_DEST_VAR/$SOURCE_FILE
then
echo 'SFTP complete'
else
echo 'SFTP failed!'
exit 1
fi
#Step 2 - Check that ftp was successful (that the files exist)
if [ -e $WS_BLOG_DEST_VAR/$SOURCE_FILE ]
then
echo "FTP of $WS_BLOG_SOURCE_VAR/$SOURCE_FILE from $WS_BC_SERVER1 was successful"
else
echo "FTP of $WS_BLOG_SOURCE_VAR/$SOURCE_FILE from $WS_BC_SERVER1 was not successful!"
exit 1
fi
done < blogs_array.txt
exit 0
你認爲'sftp.pl'正在工作嗎?你想發佈一個鏈接到'stfp.pl'(或腳本本身,如果夠短)嗎? – thb 2012-04-05 19:28:41
99次出100問題是sftp.pl行上的一個參數中有一個空格,導致參數亂序結束。嘗試將所有參數封裝在sftp.pl中,使用雙字節''' – Petesh 2012-04-05 19:33:29