我正在使用下面的代码从 SFTP 服务器下载文件并且能够做到这一点,但在尝试解压缩下载的文件时遇到问题。
下面是代码:
#!/bin/bash
sudo yum -y install expect
cd /mnt/Additional_Backup/SFTP_Scripts/
################################ Unzipping file MDTR ################################
if [ "$1" = "ARG1" ]; then
rm RemoteFileList.txt
echo ''> RemoteFileList.txt
expect -c "
spawn sftp -o StrictHostKeyChecking=no [email protected]:/
expect \"Enter password:\"
send \"*********\n\"
expect \"sftp>\"
log_file -noappend RemoteFileList.txt
send \"ls -1t\n\"
expect \"sftp>\"
log_file
expect \"sftp>\"
send \"bye\n\"
interact
"
sed '1c\''' RemoteFileList.txt > text1.txt
head -n 2 text1.txt > arguments.txt
head -n 1 arguments.txt > arg1
tail -n 1 arguments.txt > arg2
read file1 < arg1
read file2 < arg2
rm -fv arg*
rm text1.txt
rm RemoteFileList.txt
cd /mnt/Additional_Backup/SFTP_Scripts/$1/
expect -c "
set timeout 1000
spawn sftp -o StrictHostKeyChecking=no [email protected]
expect \"Enter password:\"
send \"********\r\"
expect \"sftp>\"
send \"cd /mnt/Additional_Backup/SFTP_Scripts/$1/\r\"
expect \"sftp>\"
send \"get $file1\r\"
expect {
"*100%*" { }
timeout { exit 2 }
}
expect \"sftp>\"
send \"get $file2\r\"
expect {
"*100%*" { }
timeout { exit 2 }
}
expect \"sftp>\"
send \"bye\r\"
expect eof
"
echo "Unzipping ARG1 files in progress"
unzip -o "$file1"
unzip -o "$file2"
echo 'All unzip done."
fi
但是在调试脚本时我得到了低于o/p的值:
+ echo Unzipping MMIT files in progress
Unzipping MMIT files in progress
+ unzip -o $'MMITPARFeed2.0_06_01_2020.zip\r'
.ZIP.or MMITPARFeed2.0_06_01_2020.ziped2.0_06_01_2020.zip
+ unzip -o $'MMITDataFeed2.0_06_01_2020.zip\r'
.ZIP.or MMITDataFeed2.0_06_01_2020.ziped2.0_06_01_2020.zip
+ echo 'All unzip done. Deleting existing folders from HDFS.'
All unzip done.
当我手动运行 unzip 命令时它工作正常。
我认为我在这里没有获得+ unzip -o $'MMITDataFeed2.0_06_01_2020.zip\r'
提取文件的确切值。
我尝试过使用tar
以及jar
命令。
有人可以帮我解决同样的问题吗?
提前致谢...!!!