New to JSON creation, decided to try JQ from this question. However, when I tried implementing it, all I received was the help page for JQ and these types of errors: ./test.sh: line 43: --: command not found
for the last three lines.
#!/bin/bash
echo Starting
sensorType="XXX"
sensorLocation="XXX"
sensorCommand="XXXXX"
# Hardware information.
systemTime=$(date +%d-%m-%Y_%H:%M:%S)
kernalName=$(uname -s)
nodeName=$(uname -i)
kernalRelease=$(uname -r)
kernalVersion=$(uname -v)
machine=$(uname -m)
processor=$(uname -p)
hardwarePlatform=$(uname -i)
operatingSystem=$(uname -o)
timeup=$(uptime)
# Software information.
softVersion=$(XXX version)
JSON_STRING=$( jq -n \
-- arg systemTime "$systemTime" \
-- arg sensorType "$sensorType" \
-- arg sensorLocation "$sensorLocation" \
-- arg sensorCommand "$sensorCommand" \
-- arg kernalName "$kernalName" \
-- arg nodeName "$nodeName" \
-- arg kernalRelease "$kernalRelease" \
-- arg kernalVersion "$kernalVersion" \
-- arg machine "$machine" \
-- arg processor "$processor"
-- arg hardwarePlatform "$hardwarePlatform" \
-- arg operatingSystem "$operatingSystem" \
-- arg timeup "$timeup" \
-- arg softVersion "$softVersion" \
'{systemTime: $systemTime, sensorType: $sensorType, sensorLocation: $sensorLocation, kernalName: $kernalName, nodeName: $nodeName, kernalRelease: $kernalRelease, machine: $machine, processor: $processor, hardwarePlatform: $hardwarePlatform, operatingSystem: $operatingSystem, timeup: $timeup, softVersion: $softVersion }' )
echo $JSON_STRING
Not sure if this is the most efficient way of using JQ or if there is a better way to implement it. But I would love to hear if there is a more efficient / easier way to accomplish this.