Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a script I made to create a backup. I need to make sure the backup is ready before it runs the /home/ftp.sh command. How can I do so? I use CentOS 5.6

#!/bin/bash
tar -Pcf /home/temp_backup.tar /home/myfiles/
wait %%
/home/ftp.sh
share|improve this question
5  
Currently you don't have any programs backgrounded, so your invocation of wait makes no sense. How are you defining "backup is ready"? It looks fine to me in its current state (although the spurious wait is unnecessary). –  Chris Down Dec 10 '11 at 0:06
    
I mean wait untill tar -Pcf /home/temp_backup.tar /home/myfiles/ finish because its huge folder might take up to minute and only when its finished run /home/ftp.sh –  Hujeplet Dec 10 '11 at 1:12
2  
we understand what you mean, @Hujeplet, but what @chris-down was saying is that your tar command is not being backgrounded, so the script has no choice but to wait for it to finish before executing the /home/ftp.sh script. –  Tim Kennedy Dec 10 '11 at 1:19
3  
@Hujeplet - But it already does that... –  Chris Down Dec 10 '11 at 1:20
add comment

2 Answers

You're already doing it.

Waiting for a command to finish is the shell's normal behavior. (Try typing sleep 5 at a shell prompt.) The only time that doesn't happen is when you append & to the command, or when the command itself does something to effectively background itself (the latter is a bit of an oversimplification).

You can delete the wait %% command from your script; it probably just produces an error message like wait: %%: no such job. (Question: does it actually print such a message?)

Do you have any evidence that the tar command isn't completing before the /home/ftp.sh command starts?

Incidentally, it's a bit odd to have things other than users' home directories directly under /home.

(I know most of this was already covered in comments, but I thought there should be an actual answer.)

share|improve this answer
add comment

You can use:

wait $!

Delete the wait %% from your script.

share|improve this answer
    
As explained in Keith's answer, any wait command is completely unnecessary. –  Kazark Mar 29 '13 at 18:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.