我已经在我的机器上安装了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
发布于 2019-03-16 02:59:17
您可以使用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中调度查询并将结果推送到日志管道中是一种常见的用例。
发布于 2019-03-14 21:48:01
osqueryi通常用于交互式使用。当保存到文件中,或者让osquery成为数据管道的一部分时,人们通常会使用osqueryd来配置预定的查询。
https://osquery.readthedocs.io/en/stable/deployment/configuration/有一些非常简单的配置示例。
您还可以在命令行上指定查询,然后在shell中执行任何操作。
https://stackoverflow.com/questions/55160888
复制相似问题