The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pause() problems IdleProc UNIX for Dummies Questions & Answers 1 03-17-2009 06:21 PM
Pause for response from the log file gxdanh Shell Programming and Scripting 3 10-24-2008 12:52 PM
Rsync script in cron from stepping on itself sunsysadm2003 Shell Programming and Scripting 3 04-30-2008 12:14 PM
pause? where art thou? 01000101 High Level Programming 3 05-15-2006 08:42 PM
how to pause another process? daneensign UNIX for Dummies Questions & Answers 1 02-14-2006 12:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-26-2009
droppedonjapan droppedonjapan is offline
Registered User
  
 

Join Date: May 2008
Posts: 8
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 (permalink)  
Old 05-26-2009
in2nix4life's Avatar
in2nix4life in2nix4life is offline
Registered User
  
 

Join Date: Oct 2007
Location: East Coast
Posts: 58
If this is a Bash shell script you could try the 'wait' command.

See more here - Job Control Commands

Hope this helps.
  #3 (permalink)  
Old 05-26-2009
jaysunn's Avatar
jaysunn jaysunn is offline
Registered User
  
 

Join Date: May 2009
Posts: 22
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 (permalink)  
Old 05-28-2009
droppedonjapan droppedonjapan is offline
Registered User
  
 

Join Date: May 2008
Posts: 8
Quote:
Originally Posted by in2nix4life View Post
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. )

EDIT: Also, I'm running all this on a Red Hat system. Forgot to include that earlier.
  #5 (permalink)  
Old 06-01-2009
d.f. d.f. is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 5
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0