Tutorial :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:

ssh -N -L5903:localhost:5903 username@example.com &
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.


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »