I have the below script to pull the file from another server.
#!/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
But it is getting struck for a very long time just like below and not getting completed at all.
$ 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
I even tried adding Timeoutparameter for 20 Secs, that is also not working.
But when I run the SFTP block manually on CLI, it is working well and as expected.
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
Any idea on how do we resolve this?
bash, the shebang is#!/bin/bash, it's not clear what your interactive shell is, butsh -x AWS_CRED_COPY.shusessh. I'm not saying this is the culprit; I'm saying it's good not to randomly switch shells when testing.