How to Start a Horizon Session from a Linux Command Line

This is the third and final article in a series on starting the Horizon Client from the command line. In the first article, I walked through how to launch the Horizon Client to a Horizon desktop using a .bat file. In the second article, I showed how I added a .bat file to the taskbar and Start menu which could automatically log me in to a Horizon streaming application. Being that I was already down this rabbit hole, I figured it would be worthwhile to go one step further; in this article, I will go over how to start a Horizon session from the Linux command line, even if you are not on the GUI.

If you are not familiar using the vmware-view command, I highly recommend first reading the articles mentioned above.

On a Linux system, the executable file for the Horizon Client is located at /usr/bin/vmware-view. Entering VMware-view -h shows that it has many of the same features as it does on a Windows system. However, a few of the switches are slightly different and the arguments to the switches are prefaced with a double dash with an equal sign connecting them, as shown here:.

[Click on image for larger view.]

To test connecting to a Horizon desktop from a Linux desktop, I entered the following:

/usr/bin/vmware-view  --desktopName=Hrz8ICPA --userName=vuser01@fentronics --password=nope --desktopSize=large --serverURL= --monitors=1 --nonInteractive --unauthenticatioedAcccessEnabled=TRUE &

After entering the command, I was connected to a Horizon desktop. The "&" at the end of the command ran the process in the background so I could run other commands from the command line.

To kill the job, I entered: kill %%.

Next, I wanted to be able to start the session from an remote connection that I SSH’ed to the machine. To do this, I entered xhost + on the command line on the GUI, then I appended --display=:0.0 to it to have it start on graphics display. The full command is:

/usr/bin/vmware-view  --desktopName=Hrz8ICPA --userName=vuser01@fentronics --password=nope --desktopSize=large --serverURL= --monitors=1 --nonInteractive --unauthenticatioedAccessEnabled=TRUE --display=:0.0 &

The whole point of me doing this was to demonstrate the monitoring software I needed in order to have an active desktop always running. To mimic a user logging off and reconnecting, I created the following Bash script:

## This script will run a horizon desktop indefinitely 
## If it is run remotely xhost + must be run on the GUI
while true
        ## Start a Horizon session in the background 
        /usr/bin/vmware-view  --desktopName=Hrz8ICPA --userName=vuser01@fentronics 
        --password=nope --desktopSize=large --serverURL= --monitors=1 
        --nonInteractive --unauthenticatioedAccessEnabled=TRUE --display=:0.0 &
        ## restart the session every four hours
        sleep 14400
        pkill -u root vmware-view
        sleep 60

Whether you use the vmware-view command in a .bat file on a Windows machine to instantiate a connection to a Horizon desktop or application with a single click, or use it in a Linux Bash script, I am sure you find this to be a useful tool.

About the Author

Tom Fenton has a wealth of hands-on IT experience gained over the past 30 years in a variety of technologies, with the past 20 years focusing on virtualization and storage. He previously worked as a Technical Marketing Manager for ControlUp. He also previously worked at VMware in Staff and Senior level positions. He has also worked as a Senior Validation Engineer with The Taneja Group, where he headed the Validation Service Lab and was instrumental in starting up its vSphere Virtual Volumes practice. He's on X @vDoppler.


Subscribe on YouTube