SSH Is hanging and the & sign does not seem to be working

I am having an issue where I am do an SSH to about 30 servers one at a time however my script is getting hung up sometimes on the SSH.
I thought the & at the end as seen below would fire it and move on but that does not seem to be working.

#!/bin/sh
for remsys in trumpetsnail angel delphin kraken bluemarron penguinshrimp moccasin roughgreen bluegarter eastindigo penribbon ringneck banded bl
ackracer applesnail skimmerclam seaclam
do
/lcl/tools/bin/sshPing.pl $remsys
VAR=$`/usr/bin/ssh $remsys "/lcl/apps/Tivoli/netcool/omnibus/bin/syslog_mon.sh" 2>&1 &`
Results=${VAR}
echo $Results
done

Any ideas?

The ssh connection will be waiting for the password to be supplied.

The solution for this is to exchange keys with the servers you are trying to login to, otherwise you need to supply password for each and every ssh to $remsys.

Also you first line is not correct, pass a proper shell.

Regards,
Vishal

Passwording is not an issue. We use a .hosts file which allows for an SSH to each server from one another.
The first line was just a type'o in here. :slight_smile:

Any other ideas?

What happens if you add a -n as option for ssh?

You can't get a result from backticks if you put the thing into the background. To know what the output is, it has to be able to know what the output is -- i.e. either you'll get nothing, or it'll wait until it finishes.

Correct but is there someway to make that timeout?

Either have your script going for the timeout somehow or let ssh handle it (3 seconds for example):

ssh -o ConnectTimeout=3 ...

What I do in my own parallel ssh script is redirect their output into individual files, background them, and wait for them individually. When they return, I read and delete the temp files.

That may be exactly what I am looking for. I did not know there was a ConnectTimeout setting for SSH. what does the -o stand for?

It stands for man ssh.

I see....
-o 'option' Process the option as if it was read from a configuration file.

I will give this a try.

---------- Post updated at 07:38 AM ---------- Previous update was at 07:35 AM ----------

Hhhhhmmmm it is kicking back to me...

Bad configuration option: ConnectTimeout

Post the line you used, thanks.

ssh -o ConnectTimeout=15 eventsit

That line looks very correct; as Corona688 said, check your man page for the option of ssh on your box or just issue

ssh --help

I've never backgrounded a backtic expression before. That looks to me like a recipe for disaster. First, it won't do any parallelization of your foreground task. SecNod, you get no error code. But I think at least it closed STDIN which is why -n might be superfluous.

If you are still frustrated with this, I highly recommend the "pdsh" suite.. It actually parallelizes the ssh connection to your servers in a configurable way. However, it will not solve the "shell escape" problem that you might be suffering from

assign string to the variable and retrieve value from there.