How to wait for tar to finish before sending the archive through ftp?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to wait for tar to finish before sending the archive through ftp?
# 1  
Old 10-13-2011
How to wait for tar to finish before sending the archive through ftp?

Hey all,

I want to automate tarring a directory then using ftp to transfer the files over.

I was able to put the commands together but what I'm noticing is that only the very first file is being tarred and then transferred.
Code:
tar cvpf new.backup source

Above is the command I'm using which works fine on its own but it looks like right after the command is executed in my script the ftp command is also executed immediately after which results in bad data.

How am I supposed to get around this? Is there a way to wait for a previous command to finish?
I was reading up on subshells; putting the command in ( ) but that did not work
I also tried using it with wait.

I'm going to try and execute the command in another script and see if my shell will wait for it to finish but I'm hoping someone out there can give me some insight?

Thanks a bunch,
Erin

---------- Post updated at 07:37 PM ---------- Previous update was at 07:25 PM ----------

I got it to work this way to control the execution sequence

Code:
tar cvpf  new.backup source && echo "this is done now" >> log

My shell script will now not move forward until the first command argument has succeeded then it will process the echo statement Smilie

Is there any alternatives to this? I would love to hear them
Does anyone see any issues with the way I'm doing this?
# 2  
Old 10-13-2011
It really depends on how your FTP script works. If those commands were in the same script just run line-by-line, it'd wait for tar to finish. You're running two separate scripts and connecting them somehow...

Could you show how you do the whole procedure, not just the tar end?
# 3  
Old 10-14-2011
This works
But if I remove the && operand the ftp portion executes immediately (I think) after the tar and when I view the tar on the ftp host, it only records the first file

that very same file that gets sent over to the ftp host is fine when I look at it on the original server

Is there another way to do this?

Code:
tar cvpf ${APP_BACKUP} ${APP_SOURCE} && echo "this is done now $!" >> {$LOG}

if [ $? -eq 0 ]; then
	echo "${APP_BACKUP} Has been created" >> ${LOG}
fi

ping ${FTP_HOST} -c 2 > /dev/null 2>&1 

if [ $? -eq 0 ]; then

${CMD_FTP} -n ${FTP_HOST} <<BATCH
quote user ${FTP_USER}
quote pass ${FTP_PASS}
binary
mkdir ${BACKUP_DIR}
cd ${BACKUP_DIR}
put ${APP_BACKUP}
bye
BATCH
exit 0

else
	echo "Could not ping ${FTP_HOST}"
	exit 1
fi

# 4  
Old 10-17-2011
Quote:
Originally Posted by Keepcase
This works
But if I remove the && operand the ftp portion executes immediately (I think) after the tar and when I view the tar on the ftp host, it only records the first file
It won't execute immediately, it will wait for tar.

If you had a stray & (single) after tar, that could have put tar into the background and caused those symptoms.
# 5  
Old 10-19-2011
Thanks Corona688 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to wait for a grand child to finish?

Hello all, I have a very basic question. I have a requirement where in, I have a main process which forks a child process, which execs and runs a c executable corresponding to a daemon. In the c executable corresponding to a daemon, as everyone does, I fork another child process, and as part of... (7 Replies)
Discussion started by: sai2krishna
7 Replies

2. UNIX for Dummies Questions & Answers

Remote FTP Backup -Tar archive+ encrypt+ split to a remote ftp

I have a huge directoy(200+ gb) for backup. I want upload the tar file(split files) simultaneous to a remote ftp. (pipeline, stdout, stdin etc.) I don't want write a data to local hdd. I have a ssd hdd. thanks. this code doesn't work.( yes i know the problem is split command!) tar cvzf -... (8 Replies)
Discussion started by: tara123
8 Replies

3. Shell Programming and Scripting

How to WAIT for jobs in each group to finish?

I have the shell script to call a Perl routine and pass the Informatica WorkFlow name to it. Jobs in each group executes in background do not seem to wait at all. How do I make it to WAIT for the prior group to complete before execute the next group of jobs? Sample of the jobs flow: { ... (6 Replies)
Discussion started by: lv99
6 Replies

4. Linux

tar archive

I have made tar archive of my system.. How can I make that tar archive to be bootable.. simply to install new linux from the archived tar file.. thanks in advance (8 Replies)
Discussion started by: Vit0_Corleone
8 Replies

5. UNIX for Dummies Questions & Answers

diff between TAR+zip+FTP and TAR+FTP

Huloo, whats diff between TAR+zip+FTP and TAR+FTP,can't we simpply FTP a file without Zipping it? TAR is simply for Archiving ,then why do we need to Zip it? :( (1 Reply)
Discussion started by: swarup2008
1 Replies

6. Shell Programming and Scripting

How to wait for the subprocess to finish in tcl

Hi All Here i have a piece of code, set filename "./GopiRun.sh" #I need to wait here until the GopiRun.sh is completed how do i achive this exit. (1 Reply)
Discussion started by: nathgopi214
1 Replies

7. UNIX for Dummies Questions & Answers

Q: tar archive help

hey how do you create a archive and add file to an existing archive. i keep getting an error: dir/#: No such file or directory currently using tar -cvfu name.tar files files searching from a word document each line having different file extention. Thanks in advance (1 Reply)
Discussion started by: nookie
1 Replies

8. UNIX for Dummies Questions & Answers

Archive (tar)

Hi, I want to archive below directories ex: /home/oracle/ddd0 /home/oracle/ddd1 /home/oracle/ddd2 I want a command(tar) which will let me archive the above directories excluding *.dmp(dump files), *.log(log files) in those directories. So the archived file doesn't have... (4 Replies)
Discussion started by: dreams5617
4 Replies

9. Solaris

Urgent...FTP unable finish download file, hang half way

Hi all, I have 1 problem in my solaris 8 server. The problem is in every nite that will run a cron job to download file from external ftb server. This crob job starter running find, but after running for 4 minute, that ftp services is hang that, until we need kill this process. My question... (3 Replies)
Discussion started by: foongkt5220
3 Replies

10. UNIX for Advanced & Expert Users

How can I wait for PID to finish in another shell

Have a need to schedule programs that can run after other programs are completed. Here's the catch: 1) The list of programs will not always be the same (kind of a plug-n-play deal) 2) The invoking shell may not be the same as the shell of the program being waited on In other words, I need... (2 Replies)
Discussion started by: superdelic
2 Replies
Login or Register to Ask a Question