Shell – Wait for process to finish before going to the next line in shell script

shell-scripttar

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

Best Answer

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.)

Related Question