Preface
In an automated deployment involving shell scripts requires dynamic reading of many configuration files, preferably in JSON format.
More JQ information: http://stedolan.github.io/jq/manual/
First, the value is obtained by key
Syntax:jq '. Key '
1, single value acquisition
Cat ' . Sign ' " d25341478381063d1c76e81b3a52e0592a7c997f "
2. JSON nested parse (nested parsing)
Cat ' . Live_node_config.node1.ip ' " 192.168.10.10 "
Note: The key name of the JSON array must be an underscore "_" and cannot be "-", otherwise it cannot be resolved. Such as:
Name of the error
"Live-node-proxy-config": { "IP":"192.168.10.100", "User":"www", "pwd":"www123456" },
That's right
"Live_node_proxy_config": { "IP":"192.168.10.100", "User":"www", "pwd":"www123456" },
Small chopper!!! Here we can use curl to get exactly the same results
' https://www.tinywan.com/frontend/websocket_client/autoInstallConf ' ' . Live_node_config.node1.ip ' " 192.168.10.10 "
The-s parameter of Curl indicates: silent mode. Don't output anything, learn more about the "Curl command"
If you do not add this parameter here, the file download progress will be output as follows:
[Email protected]:~$ Curl'https://www.tinywan.com/frontend/websocket_client/autoInstallConf'| Jq'. Live_node_config.node1.ip'% Total% Received%xferd Average Speed time time dload Upload Total spent left Speed - 636 0 636 0 0 2053 0--:--:-- --:--:-- --:--:--2058"192.168.10.10"
3. Parse non-existent element, will return null
Cat ' . live_node_config.node1.ip123 ' NULL
The built-in functions of the JQ, such as: Keys,has
1. Keys is used to get the key element in the JSON, find all the keys in the JSON
[Email protected]:$ Curl'https://www.tinywan.com/frontend/websocket_client/autoInstallConf'| Jq'Keys'[ "Live-node-config", "Live-node-proxy-config", "Osscmd-config", "Push-config", "Redis-config", " Sign"]
2. Has is used to determine if there is a key
' https://www.tinywan.com/frontend/websocket_client/autoInstallConf ' ' Have ("sign") ' true [email protected]: ' https://www.tinywan.com/frontend/websocket_client/autoInstallConf ' ' Has ("sign2") ' false [email protected]:~$
Detailed description of the Linux command (11) Shell parsing JSON command JQ detailed