脚本似乎是正确的。但是,在FTP访问目录中的所有文件之后,它会给我一个错误,即它试图将目录移动到自己的目录中。
有关为何发生这种情况的任何想法?
mysql -u ????? -p????? -h ????? db < $SCRIPT_FOLDER/script.sql > script.xls
echo "###############################################################################"
echo "FTP the files"
#for FILE in `ls $SOURCE_FOLDER/`
for FILE in $SOURCE_FOLDER/*.xls
do
echo "# Uploading $SOURCE_FOLDER/$FILE" >> /tmp/CasesReport.copy.out
sshpass -p ???? sftp -oBatchMode=no -b - user@ftp << END
cd /source/directory/
put $SOURCE_FOLDER/$FILE
bye
END
echo "Moving $FILE to $SOURCE_FOLDER/history/"
mv $SOURCE_FOLDER/$FILE $SOURCE_FOLDER/history/$FILE
答案 0 :(得分:1)
$FILE
已包含$SOURCE_FOLDER
,因此您put
命令会使路径加倍。
实施例
$ cd /tmp
$ touch foo.txt bar.txt
$ cd
$ SOURCE_FOLDER=/tmp
$ for FILE in $SOURCE_FOLDER/*.txt; do echo "put $SOURCE_FOLDER/$FILE"; done
put /tmp//tmp/bar.txt
put /tmp//tmp/foo.txt
在for循环中,只需使用"$FILE"