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 am copying the files from machineB and machineC into machineA as I am running my below shell script on machineA.

If the files is not there in machineB then it should be there in machineC for sure so I will try copying the files from machineB first, if it is not there in machineB then I will try copying the same files from machineC.

I am copying the files in parallel using GNU Parallel library and it is working fine. Currently I am copying 10 files in parallel.

Below is my shell script which I have -

#!/bin/bash

export PRIMARY=/test01/primary
export SECONDARY=/test02/secondary
readonly FILERS_LOCATION=(machineB machineC)
export FILERS_LOCATION_1=${FILERS_LOCATION[0]}
export FILERS_LOCATION_2=${FILERS_LOCATION[1]}
PRIMARY_PARTITION=(550 274 2 546 278) # this will have more file numbers
SECONDARY_PARTITION=(1643 1103 1372 1096 1369 1568) # this will have more file numbers

export dir3=/testing/snapshot/20140103

find "$PRIMARY" -mindepth 1 -delete
find "$SECONDARY" -mindepth 1 -delete

do_Copy() {
  el=$1
  PRIMSEC=$2
  scp david@$FILERS_LOCATION_1:$dir3/new_weekly_2014_"$el"_200003_5.data $PRIMSEC/. || scp david@$FILERS_LOCATION_2:$dir3/new_weekly_2014_"$el"_200003_5.data $PRIMSEC/.
}
export -f do_Copy

parallel --retries 10 -j 10 do_Copy {} $PRIMARY ::: "${PRIMARY_PARTITION[@]}" &
parallel --retries 10 -j 10 do_Copy {} $SECONDARY ::: "${SECONDARY_PARTITION[@]}" &
wait    

echo "All files copied."

Problem Statement:-

With the above script at some point (not everytime) I am getting this exception -

ssh_exchange_identification: Connection closed by remote host
ssh_exchange_identification: Connection closed by remote host
ssh_exchange_identification: Connection closed by remote host

And I guess the error is typically caused by too many ssh/scp starting at the same time. That leads me to believe /etc/ssh/sshd_config:MaxStartups and MaxSessions is set too low.

But my question is on which server it is pretty low? machineB and machineC or machineA? And on what machines I need to increase the number?

On machineA this is what I can find and they all are commented out -

root@machineA:/home/david# grep MaxStartups /etc/ssh/sshd_config
#MaxStartups 10:30:60

root@machineA:/home/david# grep MaxSessions /etc/ssh/sshd_config

And on machineB and machineC this is what I can find -

[root@machineB ~]$ grep MaxStartups /etc/ssh/sshd_config
#MaxStartups 10

[root@machineB ~]$ grep MaxSessions /etc/ssh/sshd_config
#MaxSessions 10
share|improve this question

2 Answers 2

up vote 2 down vote accepted

If I understand this code correctly I believe this is your issue:

do_Copy() {
  el=$1
  PRIMSEC=$2
  scp david@$FILERS_LOCATION_1:$dir3/new_weekly_2014_"$el"_200003_5.data \
    $PRIMSEC/. || \
    scp david@$FILERS_LOCATION_2:$dir3/new_weekly_2014_"$el"_200003_5.data \
    $PRIMSEC/.
}
export -f do_Copy

parallel --retries 10 -j 10 do_Copy {} \
    $PRIMARY ::: "${PRIMARY_PARTITION[@]}" &
parallel --retries 10 -j 10 do_Copy {} \
    $SECONDARY ::: "${SECONDARY_PARTITION[@]}" &
wait    

You're running 20 scp's in parallel, but machines B & C can only handle 10 each:

#MaxStartups 10

I'd dial back those parallel lines to say 5 and see if that fixes your issue. If you want to increase the number of MaxStartups on machines B & C you could do that as well:

MaxStartups 15

And make sure to restart the sshd service on both B & C:

$ sudo service sshd restart

Confirming config file modifications

You can double check that they're working by running sshd in test mode via the -T switch.

$ sudo /usr/sbin/sshd -T | grep -i max
maxauthtries 6
maxsessions 10
clientalivecountmax 3
maxstartups 10:30:100
share|improve this answer
    
Yeah I forgot to mention, if I run 10 scp's in parallel 5 for primary and 5 for secondary, then it works fine without any issues. But for 10 each, total 20 scps in parallel, sometimes it throws that exceptions. In any case, you are saying I can increase the MaxStartups to 15 both in machineB and machineC, right? And then do the test with 20 scp in parallel to see whether this works or not? –  Webby Jun 12 at 1:23
    
Also, after making the changes in the file by increasing to 15 how can I restart sshd service on my both machines? Is there any command for that? –  Webby Jun 12 at 1:23
    
@Webby - added command at the end of the A. Yes I would start with 15, you might need to bump it up a bit higher, but experiment and and you'll know. –  slm Jun 12 at 11:42
    
Thanks slm. But one thing which is confusing me is, in my both the machines why it is commented out then? By default it takes some value automatically? –  Webby Jun 13 at 22:24
    
@Webby - the commented out value is the default value. The commented out string in the config file is just a note so that you know what parameters there are and what their values are by default. It's basically built into the executables and you can override it through the config file. –  slm Jun 13 at 22:34

Consider using --sshdelay or --filter-hosts.

share|improve this answer

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.