#!/usr/bin/ksh
Archive_Dir='/apps/SrcFiles/MTCHG_GFTS/BRGR/Archive'
Source_Dir='/apps/SrcFiles/MTCHG_GFTS/BRGR'
cd $Source_Dir
HOST='xyz.abc.com'
USER='abcOUT'
PSW='xyzOUT'
file="Request*.pgp"
for i in 1 2 3 4 5 6
do
sftp $USER@$HOST <<END_SCRIPT
$PSW
bin
if [[ -f $file ]] ; then
#echo "File FOUND!"
mget *.pgp
bye
break
#else
#echo "File not found. Will try again in next hour!"
fi
END_SCRIPT
sleep 3600
done
What I am trying to do is check for a file using SFTP on a server and if it exists download it to local server. If it does not exist then I need to try again after another hour--but only for a maximum of 6 times. If the file does not exist at the 6th attempt the script should exit.
2 Issues:
1) SFTP without it asking for a password. I run this script and it keeps asking for a password and then gives me some random errors saying invalid command which I think is the "If file exists check". Maybe that does not work in sftp.
2) The SFTP connection has a timeout set to every 15 minutes so I want the script to create a new session everytime it looks for a file. I am not sure if my script is actually doing that.
I know that I can specify a batch file that can be used as input to allow for it to pick up the password automatically but I couldn't figure that out. Any help suggestions--welcome.