Problem with X in a script

Hello,

I'd like to open a bunch of windows on a server/servers from a script using ssh. The point is to run a tool several times (often a quite high number of times) with different parameters, but I'm substituting xeyes for that tool below. I have keys set up to log on transparently onto the server, so I tried:

#!/bin/bash

for run in `seq 1 10`
do
    ssh -X -l <my user> <server> "xeyes" &
done

However, whenever I run this, I only get a subset of instances of xeyes, anywhere between 1 and (never quite) 10. For all the missing windows, I get an error message:

Error: Can't open display: localhost:18.0
Error: Can't open display: localhost:20.0
Error: Can't open display: localhost:22.0
Error: Can't open display: localhost:23.0

Therre also seems to be issues with authentication but I don't understand what exactly because I also get a bunch of

/usr/bin/X11/xauth:  error in locking authority file /home/<user>/.Xauthority
X11 connection rejected because of wrong authentication.

Although I've tried to read up, I don't quite understand what .Xauthority is supposed to do, but I removed (well, renamed .Xauthority.bak) the file in question on the server and tried again, but the errors still occur.

Can someone explain/help/point me to better documentation than I found?
I must admit that I feel like looking for a needle in a haystack when I google the problem because I come up with tons of pages explaining how to set your DISPLAY variable and such, but that doesn't seem to be the problem here, since 1) "ssh -X" should take care of that for me 2) some of the windows are opening.

Again, using X over ssh in general works, just not when I try to start many windows on the server from within a loop. Starting them all by hand with repeated

$ ssh -X -l <user> <server> "xeyes" &
$ ssh -X -l <user> <server> "xeyes" &
$ ssh -X -l <user> <server> "xeyes" &
$ ssh -X -l <user> <server> "xeyes" &
$ ssh -X -l <user> <server> "xeyes" &
$ ssh -X -l <user> <server> "xeyes" &
$ ssh -X -l <user> <server> "xeyes" &
$ ssh -X -l <user> <server> "xeyes" &
$ ssh -X -l <user> <server> "xeyes" &
$ ssh -X -l <user> <server> "xeyes" &

works fine.

In case this is relevant, I am using Xquartz 2.6.1 on a Mac to connect to a Linux (Ubuntu) box.

The .Xauthority file is generated by the xauth program, and ensures that only authorized machines/users may use your display.

My first guess would be that it's a problem with concurrency, creating race conditions on the .Xauthority file, and maybe even on the sockets for the X11 connection. Try adding a short sleep (1 second should be enough) after each started SSH connection.

When I tried this, I got the same results as you.
(I don't need -X or -l because of my configuration.)

for x in $(seq 1 10); do ssh <server> xeyes & done

But this works, at least for me.

for x in $(seq 1 10); do ssh <server> xeyes & sleep 0.1; done

---------- Post updated at 07:07 AM ---------- Previous update was at 07:05 AM ----------

pludi! You beat me by mere seconds.

Incredible... You guys have just solved in mere minutes a problem I've been struggling with for two years! Those "thanks" come from the heart... :slight_smile: