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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop to check for file before ftp

Status
Not open for further replies.

lovej

Programmer
May 13, 2002
9
US
Hi,

I am trying to create a loop to check to see if file exists on machinea before I ftp filea to machineb using unix commands. I need this loop to continue to check for filea on machinea until it exist and then ftp file to machineb.

Thanx.
 
And what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi don't have anything right now. I am trouble shooting this problem.
 
man cron, sleep and find for starters. There are probably other threads dealing with this issue - try a keyword search in the forum (and other *nix forums on Tek-Tips) for ideas.
 
I would use cron, ssh (with no logins), sftp, find or if you know the path already ls is fine. I would use the output of ls -l or something also to get the file size and verify the file transferred properly.
 
be sure to keep in mind that the file has to be complete before transferring it to machineb.


regards,

R.
 
Below is not tested, but should work; like suggested above the file may still being written to so it may be worth checking that the file size isn't growing.



while [ $size != $newsize ];do

size=`ls -al filename | awk '{print $5}'`
sleep 5
newsize=`ls -al filename | awk '{print $5}'`

while [ "$a" != "ok" ];do

ls filename > /dev/null 2>&1

if [ $? != "0" ];then
echo "Failed"
a="failed"
else
echo "File is available"
a=ok
fi

done
done

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top