Jq stuff: Difference between revisions

From SoftwareGuy
Jump to navigation Jump to search
Mark (talk | contribs)
Mark (talk | contribs)
No edit summary
Line 9: Line 9:
Fancy way to find the scanId of a selected system via bash and jq
Fancy way to find the scanId of a selected system via bash and jq


<code>if [ -z $1 ]; then whichIE="uvx"; else whichIE=$1; fi</code>
<code>if [ -z $1 ]; then whichIE="uvx"; else whichIE=$1; fi
 
printf ".lastVehicleRecord.scans[] | select(.type | endswith(\""$whichIE"\"))\n" > parms.jq
<code>printf ".lastVehicleRecord.scans[] | select(.type | endswith(\""$whichIE"\"))\n" > parms.jq</code>
wget -qO heartbeat <nowiki>http://$ip/heartbeat</nowiki>
 
cnt=$(jq '.lastVehicleRecord.scans | length' heartbeat)
<code>wget -qO heartbeat <nowiki>http://$ip/heartbeat</nowiki></code>
id=$(jq -f parms.jq heartbeat | jq '.id')
 
if [ ! -z $id ]; then
<code>cnt=$(jq '.lastVehicleRecord.scans | length' heartbeat)</code>
    wget -qO $id.orig.tiff <nowiki>http://$ip/requestImage/?scanId=$id</nowiki>
 
fi</code>
<code>id=$(jq -f parms.jq heartbeat | jq '.id')</code>
 
<code>if [ ! -z $id ]; then</code>
 
<code>    wget -qO $id.orig.tiff <nowiki>http://$ip/requestImage/?scanId=$id</nowiki></code>
 
<code>fi</code>

Revision as of 15:53, 20 March 2023

Using jq

Parsing

Command to return the id number of the last scan:

cnt=$(jq '.lastVehicleRecord.scans | length' heartbeat)

Fancy way to find the scanId of a selected system via bash and jq

if [ -z $1 ]; then whichIE="uvx"; else whichIE=$1; fi printf ".lastVehicleRecord.scans[] | select(.type | endswith(\""$whichIE"\"))\n" > parms.jq wget -qO heartbeat http://$ip/heartbeat cnt=$(jq '.lastVehicleRecord.scans | length' heartbeat) id=$(jq -f parms.jq heartbeat | jq '.id') if [ ! -z $id ]; then     wget -qO $id.orig.tiff http://$ip/requestImage/?scanId=$id fi