Script Pause Until Rsync Is Done Transferring


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Pause Until Rsync Is Done Transferring
# 1  
Old 05-26-2009
Script Pause Until Rsync Is Done Transferring

Alright, I have this script that pulls files from a few locations, process those files, creates a zip file, rsync's it and then removes everything.

The problem that I'm having is that I do not know how large the rsync'ed zip file is going to be. Right now I'm using a sleep command before I remove all the files and directories created, however I'm uncomfortable in leaving it like this. All it would take would be a large file that it needs to rsync and the script would delete the file before it's done being transferred.

So, is there a way of having the script check the progress of rsync? If not, how would I go about doing something along these lines?
# 2  
Old 05-26-2009
If this is a Bash shell script you could try the 'wait' command.

See more here - Job Control Commands

Hope this helps.
# 3  
Old 05-26-2009
I like to use a lock file. This way the script will loop till lock file is gone than re execute:
Code:
#
# create name for lock file
#
lockDir="/root/lock_files"
lockFilePath="$lockDir/file.lock"
#
#
#
# Loop through servers until file is no longer exists
#  
while [ -e "$lockFilePath" ]
do

   exit
done
#
#
#
# create new lock file
#
touch $lockFilePath
#
#
#
# loop through servers and sync docroots and code
#
/usr/bin/rsync  --stats -e ssh -rlvtgoDz --delete  /dir/dir/dir/ root@server:/dir/dir/dir/ &
#
#
#
# Remove lock file........
#
rm -f $lockFilePath


Be sure to set up ssh keys. This is run on a Red Hat system.

Good Luck
# 4  
Old 05-28-2009
Quote:
Originally Posted by in2nix4life
If this is a Bash shell script you could try the 'wait' command.
For some reason the wait command doesn't work according to the documentation that you gave me. I've tried just doing this...

Code:
rsync -urza -e "ssh -i rsync-key -l username -p xxxx" /filepath/filename.zip webserv:/filepath/

wait

And it doesn't wait at all.

As for the lockfile, I'm not sure what that script does, exactly.

Code:
lockDir="/root/lock_files"
lockFilePath="$lockDir/file.lock"

while [ -e "$lockFilePath" ]
do

   exit
done

touch $lockFilePath

/usr/bin/rsync  --stats -e ssh -rlvtgoDz --delete  /dir/dir/dir/ root@server:/dir/dir/dir/ &

rm -f $lockFilePath

As far as I can tell, it starts out telling where the lock directory and file is. Then you say if the locked file exists, then if it does, then exit the script. Then if it isn't there, then you touch the file (thereby creating a blank file, if my "touch" knowledge is correct), and then starts the rsync in a background process. After it starts making the rsync, it then removes the lock file.

I could see this somewhat working if you made the script call itself before the while statement, but I don't know how this would improve my situation. Normally my script then removes the files that are being rsync'ed, so even if I called this script externally, the rm command would go through just as soon as this script finished, a la just as the rsync starts. And I really don't need to rsync multiple files, just one.

Any other ideas / suggestions?

(Thanks for what I have so far, by the way. Smilie)

EDIT: Also, I'm running all this on a Red Hat system. Forgot to include that earlier.
# 5  
Old 06-01-2009
If I understand this correctly, you're looking for a way to make sure that the rsync completes successfully before moving on to the rest of your script. bash would allow you to do this with the '&&' operator (in this case rsync is command1 ):

Code:
command1 && command2

From the bash man page, "command2 is executed if, and only if, command1 returns an exit status of zero."

So, something you might be able to use would be :

Code:
rsync -options file.xx remotehost:/path/to/store && rm file.xx

The gotcha here is that rsync can fail for a couple different reasons and if it does, the second command would not execute.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rsync Error: rsync: link_stat failed: No such file or directory (2)

I wish to copy all the files & folder under /web/Transfer_Files/data/ on mymac1 (Linux) to remote server mybank.intra.com (Solaris 10) /tmp/ location I am using Ansible tool synchronize module which triggers the unix rsync command as below:rsync --delay-updates -F --compress --archive --rsh=ssh... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

How can we overcome Broken pipe error during scp,SFTP,Rsync while transferring big files.?

Hello All, Hope all are doing well. We use scp (some times sftp and rsync also) for transferring big files (around 2GB each ) from 1 Network to another Network. The Issues which we face :- During transfer some times( Once in 1 week (or twice)) , the speed of transfer gets down to 30 kb/s,... (2 Replies)
Discussion started by: Upendra Bhushan
2 Replies

3. Shell Programming and Scripting

Creating a script requiring a pause for user input

Hi I'm trying to create a basic script that pauses for user input to verify a file name before generating the output. I have numerous SSL certificate files which I am trying to determine the expiry date so what I'm trying to do is write a script so that is pauses to request the name of the .pem... (9 Replies)
Discussion started by: Buddyluv
9 Replies

4. Shell Programming and Scripting

How to have my ksh script pause, until something appears in the logs.?

All, Is there some way to have my KSH script pause, until the word "DONE!" appears in the logfile /logs/log.txt? Difficulty: The word "DONE!" may already be present in logs from the past. So I anticipate tail -0f may (somehow?) need to be done in the background, instead of grepping in a... (16 Replies)
Discussion started by: chatguy
16 Replies

5. Shell Programming and Scripting

Need script for transferring bulk files from one format to text format

"Help Me" Need script for transferring bulk files from one format to text format in a unix server. Please suggest (2 Replies)
Discussion started by: Kranthi Kumar
2 Replies

6. Shell Programming and Scripting

Script for transferring files

Hi Guys, I have to transfer a few files in my system . The commands to be used are as follows . Will it be possible to send the output of the following in the form of a mail . cd /export/home/teja ls -lrt Quote.java* mv Quote.java Quote.java.20121023 cp /tmp/Quote.java . ls -lrt... (2 Replies)
Discussion started by: Ravi_Teja
2 Replies

7. Shell Programming and Scripting

Pause shell script till folder doesn't change size anymore

Hi, I recently would like to write a shell script that 1. Runs in the background (can be done with "&", but i'd be happy for other solutions to keep programs running) 2. Does its stuff 3 THEN checks a specified folder for a size change over time (say, each 5 seconds. AND ONLY continues with... (9 Replies)
Discussion started by: pasc
9 Replies

8. Shell Programming and Scripting

Pause for remote computing in Telnet script

I am running a telnet script that connects to a database server and executes sql scripts. While the remote database is processing the commands within the sql scripts, my telnet script continues to send commands. Okay, that's fine. They get queued up in the remote server and executed sequentially.... (3 Replies)
Discussion started by: oldjuke
3 Replies

9. Emergency UNIX and Linux Support

rsync transferring multiple files issue

Hi, I want to specify multiple remote directories but want to transfer them in a single command with one connection with remote server. This avoids entering passwords repeatedly and is also efficient. e.g. rsync -vrt --size-only --delete user@host:/home/user1/dir1... (9 Replies)
Discussion started by: sardare
9 Replies

10. Shell Programming and Scripting

How to pause a shell script

Hi, I've written a shell script to take photos with my camera. After every picture taken, the picture is transmitted to the computer via usb and then deleted on the camera. But sometimes there's an error and the picture is not deleted and so, after a certain time, the camera chip will be... (4 Replies)
Discussion started by: McLennon
4 Replies
Login or Register to Ask a Question