[TUTORIAL] After searching for a way to automagically connect to SPICE and coming up empty handed, I've created a script for anyone with the same issue!

boiimak

New Member
Jan 21, 2021
5
6
3
22
Let me preface this by saying this is specifically for Windows. A large part of my solution actually uses the officially recommended BASH script, and what I've created is essentially a batch file that executes said script on a remote Linux machine and then copies the output to be executed by the local Remote Viewer application.
It's a pretty simple script, and most of my work on it was just adding the comments to make it easily usable by noobs like myself, so hopefully anyone is able to implement this pretty seamlessly.

The script is below in both embedded code text and .txt file format (unable to upload .bat due to forum restrictions, you'll need to change it back to bat).

Hopefully I was able to help someone, enjoy!


Code:
@echo off


set _HOST=ct100
::^^^ Sets value for ssh target (host), please use Windows SSH config file, if you don't you must either set the key path with -i argument, or enter password manually when prompted by the console.
::^^^ Example value using key:
::^^^ _HOST="-i \Path\To\mykey user@ip".
set _USER=root@pam
::^^^ Sets the Proxmox user and authentication method, default is root@pam.
set _PASSWD=6969
::^^^ Sets the password used for aforementioned auth method.
set _VMID=101
::^^^ Sets the ID of the VM to connect to.
set _NODENAME=Proxmox
::^^^ Sets the node that the target VM resides on.
set _TARGETPROXY=192.168.4.420
::^^^ Sets the IP that the remote script will query, which will also be the IP that the SPICE file points to.

:: Nothing below this line needs to be edited.
mkdir %AppData%\con2spice
rm %AppData%\con2spice\spiceproxy.vv
ssh "%_HOST%" bash /etc/spice/all.sh -u %_USER% -p %_PASSWD% %_VMID% %_NODENAME% %_TARGETPROXY%
scp "%_HOST%":/etc/spice/tmp/spiceproxy.vv %AppData%\con2spice\spiceproxy.vv
start "" "%ProgramData%\Microsoft\Windows\Start Menu\Programs\VirtViewer\Remote viewer.lnk" "%AppData%\con2spice\spiceproxy.vv"
::^^^ If you want, you can remove the quotes wrapping the last argument and the start "" portion of this command to launch Remote Viewer tied to the console window.


:: The only setup required for this script is to
:: A) Download and install OpenSSH for Windows, please keep in mind that only the client is needed. More information available here 'https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse'.
:: B) Download and install Virt Viewer for Windows, which is available here 'https://virt-manager.org/download/sources/virt-viewer/virt-viewer-9.0.tar.gz' or here 'https://virt-manager.org/download/' for latest download.
:: C) Make a file named "all.sh" in a folder named "/etc/spice" with the correct content, and also create a subdirectory of spice named "tmp".
::
:: C can be done with the following command on the remote:
:: 'mkdir -p /etc/spice/tmp && curl -o /etc/spice/all.sh https://pastebin.com/raw/gfwwaH1v %% chmod +x /etc/spice/all.sh'.
:: The above command makes the required directories and puts the BASH script in place. If you want to check out the original script, it is available here 'https://git.proxmox.com/?p=pve-manager.git;a=blob_plain;f=spice-example-sh;hb=HEAD'.
::
:: For more information on Windows SSH config files, look here 'https://www.cloudsavvyit.com/4274/how-to-manage-an-ssh-config-file-in-windows-linux/'.
::
:: If you wish to change the settings specified in the spiceproxy.vv file, please do so by adding using sed or another tool at the bottom of all.sh
::
:: And most importantly, have a good day!
 

Attachments

  • SPICE template.txt
    2.7 KB · Views: 86

querformatik

Member
Oct 18, 2013
7
1
21
Thank you very much for sharing the script. It is really helpful and working very well. I am just wondering if it really should be "rm %AppData%\con2spice\spiceproxy.vv" and not rather "rd %AppData%\con2spice\spiceproxy.vv"?
 
  • Like
Reactions: grantb

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!