Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping checking for byte count 1

Status
Not open for further replies.

vuakhobo

Technical User
Apr 22, 2004
41
0
0
US
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
 
Replace this:
while read inputline
with this:
for inputline in $(<$LOCAL_DIR/list.dat)
and this:
done < $LOCAL_DIR/list.dat
with this:
done

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ahhhhh" for loop. I got it.
Thank you PHV. It works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top