LoginSignup
1
1

More than 5 years have passed since last update.

[ ohai ] ネストされた特定の値をohaiコマンドで取得したい

Posted at

0. やりたいこと

ohaiコマンドでOS情報を取得するとき、ネストされている値だけ欲しいときがある。例えば以下のような情報がohaiコマンドで取得できるが、本当はmachineの値だけ欲しいとか、そういう状況になることがある。

[~]$ ohai kernel
{
  "name": "Linux",
  "release": "2.6.32-431.3.1.el6.x86_64",
  "version": "#1 SMP Fri Jan 3 21:39:27 UTC 2014",
  "machine": "x86_64",
  "os": "GNU/Linux",
  "modules": {
    "vboxsf": {
      "size": "37631",
      "refcount": "1"
    },
  (以下省略)

1. 解決

以下のように/(スラッシュ)を使えば値を取れる。

kernelのmachineの情報が欲しい
[~]$ ohai kernel/machine
[
  "x86_64"
]

もう一段階ネストされてても値はとれる
[~]$ ohai kernel/modules/vboxsf
{
  "size": "37631",
  "refcount": "1"
}

hashのkeyを指定しても値がとれる
[~]$ ohai kernel/modules/vboxsf/size
[
  "37631"
]


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1