I am trying to write a script that allows me to check a directory for files that i will sftp to another server.
When the file is created it creates a .ready file that is supposed to signal a file is fully created and ready to sftp. for example a file named 10312014.13.07.40.27711113 would have trailing 10312014.13.07.40.27711113.ready file as well.
i dont know how to properly check for 10312014.13.07.40.27711113.ready and if it's there sftp 10312014.13.07.40.27711113.
below is what I have so far, it's just a shell of an idea, I'm stuck and any help would be greatly appreciated.
Thanks!
#!/bin/bash
source /opt/foobar/$1/config/usrconfig.sh
source /opt/foobar/$ENV/config/$2
### foobar environment variables ###
export FTPHOST="sftpserv.foobar.com" # server to ftp to
export FTPUSR="usmssh" # ftp user id
export FTPPASS="" # ftp user password
export PATTERN= # pattern for file name to ftp
export USING_MARKER=no # using a marker file???
#export TDEMARKER="X" # pattern for marker file if no files to ftp
export FTPDIR="prod/TDE/in/" # directory to ftp to on ftp server
export DAEMONLOG=/opt/foobar/$ENV/log/TDEdeamon.log
export DAEMONSLEEP=10
export CURRDATE=`date +%Y%m%d`
export READDIR=/opt/foobar/$ENV/data/TDE/output
export TEMP=/opt/foobar/$ENV/tmp
export TDE_BACKUP=$APP_ROOT/data/TDE/backup/
cd $READDIR
if [ -f $READDIR ]
then
echo " $CURRDATE files found to send!"
else
echo "no files found in $READDIR to send!"
exit
fi
sleep 2
for i in `ls $READDIR`
do
cp $i $TDE_BACKUP
echo $i
if [ -f $i.ready ]
then
rm *.ready
/usr/bin/sftp $FTPUSR@$FTPHOST << E_O_F
cd $FTPDIR
put $i
ls -l $PATTERN*
quit
E_O_F
else
echo "No files are ready"
fi
done
.