scp/untar .tar file in parallel issue

Hi Guys,

I am facing a strange issue
while doing parallel (using & for background) scp/untar operation from my unix box to multiple unix boxes...
I am getting
tar : unexpected EOF in archive error
the code is as follows.,,,

for i in 10 
do
sh -c "scp <command> ; ssh tar -xf  <tar> -C <location>" &
done 

Please help me get rid of this,
Also please comment on reliability of SCP as i read that the issue can be due to SCP?

---------- Post updated at 01:53 PM ---------- Previous update was at 01:52 PM ----------

The code is just a skeleton, i am sure the syntax is correct

What is your OS version of the server (where you scp from) and the clients you scp and untar.
Perhaps there is a compatibility issue.
Does it work if you do it manualy ?

I belive issue is not due to SCP, it's reliable.
You do have ssh keys exchanged between the server and clients ?

Use set -x to debug the shell code.

Its the same version of OS and it doesnt happen always but occassionally it happens, and manually when i do it it wrks fine... mostly it wrks but sometimes it gives this? is it due to the matter that i m running it in parallel ?

Can you confirm that the tar archive isn't being created while it's being copied ?

A complete description would be lovely, as much detail as you can spare about the complete action and desired result.

It kind of depends what <command> is.

What are you trying to do? Extract the same archive on lots of machines at the same time you're copying it? You should stream that, not copy it, or it may hit eof before it's done.

for SERVER in server1 server2 server3
do
        ssh username@$SERVER tar -C /path/to/dest -xf - < /path/to/file.tar &
done

wait

Running 9 simultaneous ssh/scp/whatever sessions may not be a good idea, you might want to limit that.

If you can install it, you can use udpcast to stream one thing to 9 servers.

for x in 1 2 3
do
        ssh username@server$X udp-receiver '|' tar -C /path/to/dest -xf - 2> /dev/null &
done

udp-sender < file.tar
wait