add spice example script spice-example-sh
[pve-manager.git] / spice-example-sh
1 #!/bin/bash
2
3 # needs pve-manager >= 3.1-44
4
5 USERNAME=root@pam
6 PASSWORD=yoursecretpassword
7 # select VM
8 VMID=100
9
10 NODE=anodename
11 PROXY=anodename.domain.tld
12
13 DATA=`curl -k -d "username=$USERNAME&password=$PASSWORD" https://$PROXY:8006/api2/json/access/ticket`
14
15 TICKET=`echo $DATA|sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"// g'|grep -w ticket| awk -F "|" '{print $2}'`
16
17 CSRF=`echo $DATA|sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"// g'|grep -w CSRFPreventionToken| awk -F "|" '{print $2}'`
18
19 curl -k -b "PVEAuthCookie=$TICKET" -H "CSRFPreventionToken: $CSRF" https://$PROXY:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy -d "proxy=$PROXY" > spiceproxy
20
21 remote-viewer spiceproxy