我已经在机器上安装了Osquery实用程序。当我启动SQL命令时,它将输出输出到STDOUT。有什么办法可以将输出重定向到文件吗?
$ sudo osqueryi
I0314 10:57:51.644351 3958 database.cpp:563] Checking database version for migration
I0314 10:57:51.644912 3958 database.cpp:587] Performing migration: 0 -> 1
I0314 10:57:51.645279 3958 database.cpp:619] Migration 0 -> 1 successfully completed!
I0314 10:57:51.645627 3958 database.cpp:587] Performing migration: 1 -> 2
I0314 10:57:51.646088 3958 database.cpp:619] Migration 1 -> 2 successfully completed!
Using a virtual database. Need help, type '.help'
osquery>
osquery>
osquery> SELECT * from memory_info;
+--------------+-------------+----------+----------+-------------+-----------+----------+------------+-----------+
| memory_total | memory_free | buffers | cached | swap_cached | active | inactive | swap_total | swap_free |
+--------------+-------------+----------+----------+-------------+-----------+----------+------------+-----------+
| 513617920 | 270921728 | 15110144 | 99860480 | 0 | 145080320 | 59494400 | 0 | 0 |
+--------------+-------------+----------+----------+-------------+-----------+----------+------------+-----------+
osquery>
我希望将此输出保存在文件中。我检查了Osquery的官方文档。但是解决这个特定问题并没有帮助。 https://osquery.readthedocs.io/en/stable/introduction/sql/#sql-as-understood-by-osquery
答案 0 :(得分:1)
osqueryi通常用于交互使用。当保存到文件或将osquery包含在数据管道中时,人们通常使用osqueryd配置计划的查询。
https://osquery.readthedocs.io/en/stable/deployment/configuration/有一些非常简单的配置示例。
您还可以在命令行上指定查询,然后在外壳程序中执行任何操作。
答案 1 :(得分:1)
您可以使用Shell的重定向功能:
$ osqueryi --json 'select * from osquery_info' > res.json
$ cat res.json
[
{"build_distro":"10.12","build_platform":"darwin","config_hash":"e7c68185a7252c23585d53d04ecefb77b3ebf99c","config_valid":"1","extensions":"inactive","instance_id":"38201952-9a75-41dc-b2f8-188c2119cda1","pid":"26255","start_time":"1552676034","uuid":"4740D59F-699E-5B29-960B-979AAF9BBEEB","version":"3.3.0","watcher":"-1"}
]
请注意,在此示例中,我们使用JSON输出。还有其他选项:--csv
,--line
,--list
。
如seph在https://stackoverflow.com/a/55164199/491710中所述,在osqueryd
中安排查询并将结果推送到日志记录管道是常见的用例。