linux下json工具jq
1、查看json文件
[root@VM-1-10-11 f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b]# pwd
/data1/docker/containers/f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b
[root@VM-1-10-11 f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b]# ls
config.v2.json hostconfig.json hostname hosts resolv.conf resolv.conf.hash secrets shm
[root@VM-1-10-11 f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b]#
[root@VM-1-10-11 f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b]# cat config.v2.json
{"StreamConfig":{},"State":{"Running":true,"Paused":false,"Restarting":false,"OOMKilled":false,"RemovalInProgress":false,"Dead":false,"Pid":9173,"StartedAt":"2017-02-09T03:46:15.709079233Z","FinishedAt":"0001-01-01T00:00:00Z","Health":null},"ID":"f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b","Created":"2017-02-08T13:33:52.903241912Z","Managed":false,"Path":"/sbin/init","Args":[],"Config":{"Hostname":"shibing.zhao-162-200","Domainname":"","User":"","AttachStdin":true,"AttachStdout":true,"AttachStderr":true,"Tty":true,"OpenStdin":true,"StdinOnce":true,"Env":["IDC=beebank","CONTAINER_NAME=shibing.zhao_172.16.162.200"],"Cmd":["/sbin/init"],"Image":"migrate.i.beebank.com:5000/shibing.zhao_172.16.162.200","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{}},"Image":"sha256:a2b61eaadc77aff698d7c9ebc1f0837ee0e5be1942f81b528f7a56e2e3ca257b","NetworkSettings":{"Bridge":"","SandboxID":"8fe25ef4a2a25902d1a56ad1a3a096d24e5955d4045fb4b34429c6575e570bb4","HairpinMode":false,"LinkLocalIPv6Address":"","LinkLocalIPv6PrefixLen":0,"Networks":{"none":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"f989ab193573c45f2d337e5752334afcb5b49d4b97efb2299743c4de3311d97a","EndpointID":"fc95bc1a8306daff737d1dbc135bd107b83226a5e01cdecb8b68b5c7f4dde249","Gateway":"","IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":""}},"Service":null,"Ports":{},"SandboxKey":"/var/run/docker/netns/8fe25ef4a2a2","SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null,"IsAnonymousEndpoint":false},"LogPath":"","Name":"/shibing.zhao_172.16.162.200","Driver":"devicemapper","MountLabel":"","ProcessLabel":"","RestartCount":0,"HasBeenStartedBefore":false,"HasBeenManuallyStopped":false,"MountPoints":{"/data2":{"Source":"/data1/docker_volume/shibing.zhao_172.16.162.200/data","Destination":"/data2","RW":true,"Name":"","Driver":"","Relabel":"","Propagation":"rprivate","Named":false,"ID":""},"/data3":{"Source":"/data1/docker_volume/user/shibing.zhao","Destination":"/data3","RW":true,"Name":"","Driver":"","Relabel":"","Propagation":"rprivate","Named":false,"ID":""},"/etc/hosts":{"Source":"/data1/docker_volume/shibing.zhao_172.16.162.200/hosts","Destination":"/etc/hosts","RW":true,"Name":"","Driver":"","Relabel":"","Propagation":"rprivate","Named":false,"ID":""},"/etc/mnt":{"Source":"/data1/docker_volume/shibing.zhao_172.16.162.200/config","Destination":"/etc/mnt","RW":false,"Name":"","Driver":"","Relabel":"ro","Propagation":"rprivate","Named":false,"ID":""},"/etc/pam_ldap.conf":{"Source":"/etc/pam_ldap.conf.beebank","Destination":"/etc/pam_ldap.conf","RW":false,"Name":"","Driver":"","Relabel":"ro","Propagation":"rprivate","Named":false,"ID":""},"/etc/resolv.conf":{"Source":"/etc/resolv.conf","Destination":"/etc/resolv.conf","RW":false,"Name":"","Driver":"","Relabel":"ro","Propagation":"rprivate","Named":false,"ID":""},"/etc/yum.repos.d/bee.repo":{"Source":"/data1/docker_volume/beebank.repo","Destination":"/etc/yum.repos.d/bee.repo","RW":false,"Name":"","Driver":"","Relabel":"ro","Propagation":"rprivate","Named":false,"ID":""}},"AppArmorProfile":"","HostnamePath":"/data1/docker/containers/f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b/hostname","HostsPath":"/data1/docker_volume/shibing.zhao_172.16.162.200/hosts","ShmPath":"/data1/docker/containers/f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b/shm","ResolvConfPath":"/etc/resolv.conf","SeccompProfile":"","NoNewPrivileges":false}
[root@VM-1-10-11 f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b]#
2、使用jq解析json文件内容
[root@VM-1-10-11 f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b]# cat config.v2.json |jq
{
"StreamConfig": {},
"State": {
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"RemovalInProgress": false,
"Dead": false,
"Pid": 9173,
"StartedAt": "2017-02-09T03:46:15.709079233Z",
"FinishedAt": "0001-01-01T00:00:00Z",
"Health": null
},
"ID": "f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b",
"Created": "2017-02-08T13:33:52.903241912Z",
"Managed": false,
"Path": "/sbin/init",
"Args": [],
"Config": {
"Hostname": "shibing.zhao-162-200",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"IDC=beebank",
"CONTAINER_NAME=shibing.zhao_172.16.162.200"
],
"Cmd": [
"/sbin/init"
],
"Image": "migrate.i.beebank.com:5000/shibing.zhao_172.16.162.200",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"Image": "sha256:a2b61eaadc77aff698d7c9ebc1f0837ee0e5be1942f81b528f7a56e2e3ca257b",
"NetworkSettings": {
"Bridge": "",
"SandboxID": "8fe25ef4a2a25902d1a56ad1a3a096d24e5955d4045fb4b34429c6575e570bb4",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Networks": {
"none": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "f989ab193573c45f2d337e5752334afcb5b49d4b97efb2299743c4de3311d97a",
"EndpointID": "fc95bc1a8306daff737d1dbc135bd107b83226a5e01cdecb8b68b5c7f4dde249",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": ""
}
},
"Service": null,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/8fe25ef4a2a2",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"IsAnonymousEndpoint": false
},
"LogPath": "",
"Name": "/shibing.zhao_172.16.162.200",
"Driver": "devicemapper",
"MountLabel": "",
"ProcessLabel": "",
"RestartCount": 0,
"HasBeenStartedBefore": false,
"HasBeenManuallyStopped": false,
"MountPoints": {
"/data2": {
"Source": "/data1/docker_volume/shibing.zhao_172.16.162.200/data",
"Destination": "/data2",
"RW": true,
"Name": "",
"Driver": "",
"Relabel": "",
"Propagation": "rprivate",
"Named": false,
"ID": ""
},
"/data3": {
"Source": "/data1/docker_volume/user/shibing.zhao",
"Destination": "/data3",
"RW": true,
"Name": "",
"Driver": "",
"Relabel": "",
"Propagation": "rprivate",
"Named": false,
"ID": ""
},
"/etc/hosts": {
"Source": "/data1/docker_volume/shibing.zhao_172.16.162.200/hosts",
"Destination": "/etc/hosts",
"RW": true,
"Name": "",
"Driver": "",
"Relabel": "",
"Propagation": "rprivate",
"Named": false,
"ID": ""
},
"/etc/mnt": {
"Source": "/data1/docker_volume/shibing.zhao_172.16.162.200/config",
"Destination": "/etc/mnt",
"RW": false,
"Name": "",
"Driver": "",
"Relabel": "ro",
"Propagation": "rprivate",
"Named": false,
"ID": ""
},
"/etc/pam_ldap.conf": {
"Source": "/etc/pam_ldap.conf.beebank",
"Destination": "/etc/pam_ldap.conf",
"RW": false,
"Name": "",
"Driver": "",
"Relabel": "ro",
"Propagation": "rprivate",
"Named": false,
"ID": ""
},
"/etc/resolv.conf": {
"Source": "/etc/resolv.conf",
"Destination": "/etc/resolv.conf",
"RW": false,
"Name": "",
"Driver": "",
"Relabel": "ro",
"Propagation": "rprivate",
"Named": false,
"ID": ""
},
"/etc/yum.repos.d/bee.repo": {
"Source": "/data1/docker_volume/beebank.repo",
"Destination": "/etc/yum.repos.d/bee.repo",
"RW": false,
"Name": "",
"Driver": "",
"Relabel": "ro",
"Propagation": "rprivate",
"Named": false,
"ID": ""
}
},
"AppArmorProfile": "",
"HostnamePath": "/data1/docker/containers/f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b/hostname",
"HostsPath": "/data1/docker_volume/shibing.zhao_172.16.162.200/hosts",
"ShmPath": "/data1/docker/containers/f46c19f56252a74a46fd30026001e62cc5ecadd04bc9a80c47f6fd5f9dc0586b/shm",
"ResolvConfPath": "/etc/resolv.conf",
"SeccompProfile": "",
"NoNewPrivileges": false
}
3、获取指定的key对应的value
[root@BASE-SERVER-1-10-10 81f7f11a8b03397d8153fdaf975a78157afee9b2279607132711e0234dbc5f3a]# cat config.v2.json |jq .State
{
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": true,
"RemovalInProgress": false,
"Dead": false,
"Pid": 114836,
"StartedAt": "2017-02-27T09:36:00.772375786Z",
"FinishedAt": "2017-02-27T09:35:41.564086153Z",
"Health": null
}
[root@BASE-SERVER-1-10-10 81f7f11a8b03397d8153fdaf975a78157afee9b2279607132711e0234dbc5f3a]# cat config.v2.json |jq .State.Running
true
linux下json工具jq的更多相关文章
- 哈工大 计算机系统 实验一 Linux下C工具应用
所有实验文件可见github 计算机系统实验整理 实验报告 实 验(一) 题 目 Linux下C工具应用 专 业 计算机学院 学 号 班 级 学 生 指 导 教 师 实 验 地 点 实 验 日 期 计 ...
- Linux下sysstat工具学习
Linux下,我们多用ssh链接服务器远程操控.对于系统的监控必不可少,sysstat很不错的监控工具包. sysstat官网:http://sebastien.godard.pagesperso-o ...
- linux如何ARP嗅探 Linux下嗅探工具Dsniff安装记录
先来下载依赖包 和一些必须要用到的工具 我这里用的是 dsniff-2.3 的版本 wget http://www.monkey.org/~dugsong/dsniff/dsniff-2.3.ta ...
- Linux下同步工具inotify+rsync使用详解
1. rsync 1.1 什么是rsync rsync是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.它使用所谓的“Rsync演算法”来使本地和远程两个主机之间的文件达到同步,这 ...
- linux下debug工具
在linux下开发难免会遇到bug,但是由于没有图形IDE,导致debug也变得困难,其实只要掌握一些常用的debug工具,一些错误就能很快解决,本文就介绍一些常用的工具用以调试: log 输出log ...
- Linux下应急工具
Linux下的应急工具 在Linux下,应急的查看点无非那个几个,一是看表现(宕机.高CPU.高内存.高IO.高网络通信),二看连接.三看进程.四看日志.五看文件(Linux一切皆文件),再者结合起来 ...
- (转)Linux下同步工具inotify+rsync使用详解
原文:https://segmentfault.com/a/1190000002427568 1. rsync 1.1 什么是rsync rsync是一个远程数据同步工具,可通过LAN/WAN快速同步 ...
- Linux下SSH工具 PAC Manager的安装
PAC Manager, Linux下类似SecureCRT Xshell的SSH工具,该工具功能上相当的不错,完全可以代替SecureCRT Xshell的功能. PAC (Perl Auto Co ...
- Linux下Vim工具常用命令
原文地址: http://www.cnblogs.com/lizhenghn/p/3675011.html 在linux下做开发,甚至是只做管理维护工作,也少不了Vim的使用.作为一个新手,我也是刚刚 ...
随机推荐
- (转)C#连接Oracle数据库(直接引用dll使用)
原文地址:http://www.cnblogs.com/gguozhenqian/p/4262813.html 项目中有个功能需要从一台Oracle数据库获取数据,本以为是很简单的事情,直接将原来的S ...
- tips:可变参数列表
tips:可变参数列表! 先来看看以往我们要传递许多参数时是怎么做的: java: public static void main(String []args){} c: int main(int a ...
- 电商系统架构总结4(webapi 版本控制)
为了 顺利迭代升级,web api 在维护过程是不断升级的,但用户是不能强迫他们每次都跟随你去升级,这样会让用户不胜其烦.为了保证不同版本的客户端能同时兼容,在web api接口上加入版本控制就很有必 ...
- mint-ui 输入框按下按键执行查询
环境:vue.mint-ui 功能:一个输入框,按下按键之后就执行某个功能. 截图:一个输入框 输入框html: <mt-search v-model="query" can ...
- 为什么TCP比UDP可靠真正原因,以及并发编程的基础问题
一 为什么TCP协议比UDP协议传输数据可靠: 我们知道在传输数据的时候,数据是先存在操作系统的缓存中,然后发送给客户端,在客户端也是要经过客户端的操作系统的,因为这个过程涉及到计算机硬件,也就是物 ...
- Apache服务器下phalcon项目报Mod-Rewrite is not enabled问题
问题如图: 项目已经按照官网的教程修改了.htaccess文件,仍旧报此错误,判断可能是apache未添加mod_rewrite,通过查询资料,经以下两步解决此问题: 1.执行sudo a2enmod ...
- ERROR: duplicate key value violates unique constraint "xxx"
在postgresql中,由于为表的主键建立了自增序列,且数据是从正式库拷贝到正式库的,所以报错如下: (主要原因:自增序列中的当前序列号小于真实数据中的最大主键值,因此在新增数据时,会报唯一值的错误 ...
- jq遍历list和object
<script> //----------------for用来遍历数组对象-- var i,myArr = [1,2,3]; for (var i = 0; i < myArr.l ...
- WPF Stake
WPF中的StackPanel.WrapPanel.DockPanel 转:http://blog.sina.com.cn/s/blog_6c81891701017a34.html StackPane ...
- chattr和lsattr命令的使用(对于root用户也无法修改删除的操作问题)
1.chattr命令的用法:chattr [+-=] [ASacdistu] File/Directory 参数说明: +-= :分别为 [+ 增加] [- 减少] [= 设定] 属性的意思 A :当 ...