我开发了一个 bash 脚本,仅当远程服务器中有特定 CSV 时才将文件移动到 FTP。另一个数据质量工具的作业调用此脚本。脚本运行良好,但它不会Control_File.csv
偶尔移动最后一个文件 () 并退出脚本。很难预测它何时会错过。下面是脚本。有什么想法可以解释为什么它不会偶尔移动最后一个文件吗?
笔记:我无法使用 SSH 密钥,这就是为什么在下面的脚本中使用期望包和屏蔽的服务器详细信息和凭据。
#!/bin/bash
today=$(date +"%Y%m%d")
LOG_LOCATION="/pken4o/shared/config/domains/edq_domain/config/fmwconfig/edq/oedq.local.home/landingarea/53/Script_Log"
exec &>> $LOG_LOCATION/File_Transfer_Log.log
printf "\nDate:$(date -u)"
lockfile="/pken4o/shared/config/domains/edq_domain/config/fmwconfig/edq/oedq.local.home/landingarea/53/DQ_Dashboard_$today.csv"
retval=0
testlock(){
if [ -e "$lockfile" ]; then
retval=1
else
retval=2
fi
}
testlock
if [ "$retval" == 1 ]
then
printf "\nDQ_Dashboard_$today.csv File exists"
expect -c "
set timeout 180
eval spawn sftp USER@SERVER
expect \"USER's password:\"
send \"PASSWORD\n\";
expect \"sftp>\"
send \"lcd /pken4o/shared/config/domains/edq_domain/config/fmwconfig/edq/oedq.local.home/landingarea/53\r\";
expect \"sftp>\"
send \"cd /HOME/IBD_EDQ/PRD\r\";
expect \"sftp>\"
send \"put DQ_Dashboard_*.csv\r\";
expect \"sftp>\"
send \"put DQD_Exceptions.csv\r\";
expect \"sftp>\"
send \"put DQD_Flag_Reactivation.csv\r\";
expect \"sftp>\"
send \"put Control_File.csv\r\";
send \"bye\r\";
expect \"sftp>\"
send \"eof\r\";
"
else
printf "\n DQ_Dashboard_$today.csv File not exists"
fi