If we’d like to test with UI program that needs a display available, this is handy to run an VNC session during the testing.
Getting Started with VNC
1 Setup a vnc server
vncserver :1
If you haven’t run a VNC server before you will be prompted for a password, which you will need to use when connecting to this server. All your servers will use the same password, and you can change it at a later date using
vncpasswd
2 Teardown a vnc server
vncserver -kill :1
3 Create a function for reuse
setup_vnc()
{
#FIX ERROR "vncserver: The HOME environment variable is not set."
[ -z "$HOME" ] && export HOME=/home/xxxtest
# default starting with :10
VNC_DISPLAY=10
# find a vnc display number hasn't been used.
while ! vncserver :$VNC_DISPLAY
do
((VNC_DISPLAY++))
done
export VNC_DISPLAY
export DISPLAY=:$VNC_DISPLAY
}
teardown_vnc()
{
vncserver -kill :$VNC_DISPLAY
}
to enable the vnc session is released, there need to trap the exit signal
trap teardown_vnc INT TERM EXIT
setup_vnc
#doing some process