GOAL:
1.Monitor remote server's folder for file(s)
2.Check and make sure file is completely copy over to the folder before sftp to another server.
Here is my reasoning.
1. Take a snap shot at current folder for list of file(s). (say we have 3 files)
2. Base on that list, get 2 reads of byte count of the first file on the list in 20 seconds
if the bytes count of the file is the same then
sftp or scp the file
break (which will go to next file on the list)
else
continue to check for bytes count
Can someone point out why it didn't go to the 2nd file on the list and check for the bytes count.
It exit as soon as the first file after it's bytes is the same after 2 reads. Or someone have better way to do it please advise.
Here is my code;
#!/usr/bin/ksh
set -x
REMOTE_DIR="/home/jcsuser/test"
LOCAL_DIR="/home/fmiciti/test"
REMOTE_SERVER="abc@abc.com"
/bin/rm $LOCAL_DIR/list.dat
ssh $REMOTE_SERVER 'ls -1 $REMOTE_DIR' >> $LOCAL_DIR/list.dat
while read inputline
do
while true
do
ssh $REMOTE_SERVER 'ls -lart $REMOTE_DIR' >$LOCAL_DIR/test1.dat
test1=$(grep $inputline test1.dat|awk '{print $5}')
echo $test1
sleep 20
ssh $REMOTE_SERVER 'ls -lart $REMOTE_DIR' > $LOCAL_DIR/test2.dat
test2=$(grep $inputline test2.dat|awk '{print $5}')
echo $test2
if [ "$test1" -eq "$test2" ]; then
ftp_file_to_another_server.ksh
break
fi
done
done < $LOCAL_DIR/list.dat
1.Monitor remote server's folder for file(s)
2.Check and make sure file is completely copy over to the folder before sftp to another server.
Here is my reasoning.
1. Take a snap shot at current folder for list of file(s). (say we have 3 files)
2. Base on that list, get 2 reads of byte count of the first file on the list in 20 seconds
if the bytes count of the file is the same then
sftp or scp the file
break (which will go to next file on the list)
else
continue to check for bytes count
Can someone point out why it didn't go to the 2nd file on the list and check for the bytes count.
It exit as soon as the first file after it's bytes is the same after 2 reads. Or someone have better way to do it please advise.
Here is my code;
#!/usr/bin/ksh
set -x
REMOTE_DIR="/home/jcsuser/test"
LOCAL_DIR="/home/fmiciti/test"
REMOTE_SERVER="abc@abc.com"
/bin/rm $LOCAL_DIR/list.dat
ssh $REMOTE_SERVER 'ls -1 $REMOTE_DIR' >> $LOCAL_DIR/list.dat
while read inputline
do
while true
do
ssh $REMOTE_SERVER 'ls -lart $REMOTE_DIR' >$LOCAL_DIR/test1.dat
test1=$(grep $inputline test1.dat|awk '{print $5}')
echo $test1
sleep 20
ssh $REMOTE_SERVER 'ls -lart $REMOTE_DIR' > $LOCAL_DIR/test2.dat
test2=$(grep $inputline test2.dat|awk '{print $5}')
echo $test2
if [ "$test1" -eq "$test2" ]; then
ftp_file_to_another_server.ksh
break
fi
done
done < $LOCAL_DIR/list.dat