2014-08-30 09:44:02 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#include <gflags/gflags.h>
|
|
|
|
#include <glog/logging.h>
|
|
|
|
|
|
|
|
#include "osquery/core.h"
|
|
|
|
|
|
|
|
DEFINE_string(query, "", "query to execute");
|
2014-09-01 21:07:53 +00:00
|
|
|
DEFINE_int32(iterations, 1, "times to run the query in question");
|
2014-11-07 01:12:40 +00:00
|
|
|
DEFINE_int32(delay, 0, "delay before and after the query");
|
2014-08-30 09:44:02 +00:00
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
2014-09-13 21:28:45 +00:00
|
|
|
osquery::initOsquery(argc, argv);
|
2014-08-30 09:44:02 +00:00
|
|
|
|
|
|
|
if (FLAGS_query != "") {
|
2014-11-07 01:12:40 +00:00
|
|
|
if (FLAGS_delay != 0) {
|
|
|
|
::sleep(FLAGS_delay);
|
|
|
|
}
|
|
|
|
|
2014-09-01 21:07:53 +00:00
|
|
|
for (int i = 0; i < FLAGS_iterations; ++i) {
|
|
|
|
int err;
|
|
|
|
LOG(INFO) << "Executing: " << FLAGS_query;
|
2014-09-16 06:07:03 +00:00
|
|
|
osquery::query(FLAGS_query, err);
|
2014-09-01 21:07:53 +00:00
|
|
|
if (err != 0) {
|
|
|
|
LOG(ERROR) << "Query failed: " << err;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
LOG(INFO) << "Query succedded";
|
2014-08-30 09:44:02 +00:00
|
|
|
}
|
2014-11-07 01:12:40 +00:00
|
|
|
|
|
|
|
if (FLAGS_delay != 0) {
|
|
|
|
::sleep(FLAGS_delay);
|
|
|
|
}
|
2014-08-30 09:44:02 +00:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Usage: run --query=\"<query>\"";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|