tags:

views:

13

answers:

1
+1  Q: 

VNC Bash Problem

I'm having a curious problem with a little script to make a VNC connection to a remote host. The script just makes an SSH tunnel for the VNC session and then opens the viewer. It's only two lines, and when copied into the shell manually, it works fine. However, invoking the script causes the VNC viewer to fail with this error: main: unable to connect to host: Connection refused (111)

Here's the script:

#!/bin/bash
ssh -N -L5903:localhost:5903 [email protected] &
vncviewer :3

The tunnel lives throughout the process, so that isn't the problem. Neither is permissions -- the same error occurs when the script is run as root. I've got public key authentication set up, so it's not that ssh is requesting a password.

What am I missing? The commands work when typed in the shell!

Thanks in advance.

+1  A: 

Most likely the vncviewer command is being executed too quickly after the ssh command. Try putting

sleep 3

between those two commands to allow time for the port forwarding to be set up.

Richard Fearn
That was exactly it. Thanks!
bgt421