我有以下脚本可以从另一台服务器中提取文件。
#!/bin/bash
PROC_DATE=`date "+%Y%m%d"`
CURRENT_DATE=`date`
LOG_FILE="/home/tdata/dw/da/common/AWS_{PROC_DATE}.log"
AWS_CRED_FILE_NAME="/home/tdata/.aws/crnals"
cp -p ${AWS_CRED_FILE_NAME} ${AWS_CRED_FILE_NAME}_${PROC_DATE}
if [ $? -ne 0 ] ; then
echo "Credentials backup Failed\n" > ${LOG_FILE}
cat ${LOG_FILE}
exit 1;
else
cd /home/tdata/.aws/
sshpass -f .OP004 sftp -o ConnectionAttempts=1 tdata@OP004 << !
cd /home/tdata/.aws/
get crnals
bye
!
if [ $? -ne 0 ]
then
echo "The credentials copy from OP004 to CP104 failed. Please check and re-run manually" > ${LOG_FILE}
cat ${LOG_FILE}
exit 1;
else
echo "The credentials copy job completed successfully on ${CURRENT_DATE}" > ${LOG_FILE}
exit 0;
fi
fi
但是就像下面一样,它被敲了很长时间,根本没有完成。
$ sh -x AWS_CRED_COPY.sh
++ date +%Y%m%d
+ PROC_DATE=20221004
++ date
+ CURRENT_DATE='Tue Oct 4 02:07:56 CDT 2022'
+ LOG_FILE=/home/tdata/dw/da/common/AWS_20221004.log
+ AWS_CRED_FILE_NAME=/home/tdata/.aws/crnals
+ cp -p /home/tdata/.aws/crnals /home/tdata/.aws/crnals_20221004
+ '[' 0 -ne 0 ']'
+ cd /home/teradata/.aws/
+ sshpass -f .OP004 sftp -o ConnectionAttempts=1 teradata@OP004
我什至尝试为 20 秒添加超时参数,这也不起作用。
但是当我在 CLI 上手动运行 SFTP 块时,它运行良好且符合预期。
tdata@cp114 -bash /opt/tdata/dw/data/common
$ sshpass -f .OP004 sftp -o ConnectionAttempts=1 teradata@OP004 << !
> cd /home/teradata/.aws/
> get crnals
> bye
> !
Connected to ODRP5004.
sftp> cd /home/teradata/.aws/
sftp> get crnals
Fetching /home/tdata/.aws/crnals to canals
sftp> bye
关于我们如何解决这个问题的任何想法?