spice-example-sh: avoid use of sed and awk
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 17 Mar 2014 11:00:00 +0000 (12:00 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 17 Mar 2014 11:00:43 +0000 (12:00 +0100)
spice-example-sh

index 45bfb131bc7e6c16fc1a4d4c893416984dff43a2..60602a262e8b56468dea84e8c36cfd1731c90585 100755 (executable)
@@ -12,9 +12,13 @@ PROXY=anodename.domain.tld
 
 DATA=`curl -k -d "username=$USERNAME&password=$PASSWORD"  https://$PROXY:8006/api2/json/access/ticket` 
 
-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}'`
+TICKET=${DATA//\"/}
+TICKET=${TICKET##*ticket:}
+TICKET=${TICKET%%,*}
 
-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}'`
+CSRF=${DATA//\"/}
+CSRF=${CSRF##*CSRFPreventionToken:}
+CSRF=${CSRF%%,*}
 
 curl -k -b "PVEAuthCookie=$TICKET" -H "CSRFPreventionToken: $CSRF" https://$PROXY:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy -d "proxy=$PROXY" > spiceproxy