I'm trying to automate the process of starting of a VNC server on a remote computer (to which I am directed automatically by a login server) and connecting to it in Bash.
The idea is that the VNC server start command is executed via SSH. The output of this command is parsed to get the details of the VNC server and then a connection is established to the VNC server.
I'm having difficulty capturing the output of the VNC server start command and would welcome any suggestions to simplify or otherwise improve the approach.
The VNC server start command executed remotely via SSH is the following:
ssh [email protected] 'vncserver'
This would produce an output such as the following:
New 'lxplus0180.cern.ch:2 (user1)' desktop is lxplus0180.cern.ch:2
Starting applications specified in /afs/cern.ch/user/u/user1/.vnc/xstartup
Log file is /afs/cern.ch/user/u/user1/.vnc/lxplus0180.cern.ch:2.log
I could parse this output in a way such as the following:
echo "${response}" | sed '/New.*desktop.*is/!d' | awk -F" desktop is " '{print $2}'
This would produce something like the following:
lxplus0180.cern.ch:2
A VNC connection then can be established using this information.
How can I record this response so that I can parse it? Is there a more efficient way of parsing this information (perhaps adding a space before the colon for the purposes of the connection command vncviewer
)? Is there generally an easier way of doing what I'm trying to do here?
The VNC server startup event passes output to the standard error output stream. This can be captured in a variable in a way such as the following:
VNCServerResponse="$(ssh "${address1}" 'vncserver' 2>&1)"