fleet/tools/osquery-testing/test-tables.sh
2022-08-17 14:36:17 -04:00

27 lines
660 B
Bash
Executable file

#!/usr/bin/env bash
# Exit if no input file provided.
[ -z $1 ] && >&2 echo "Error: Input file must be provided" && exit 1
# Read lines from input file.
cat "$1" | while read -r line
do
# Ignore comments (lines starting with #) and empty lines in the input file.
if [ "${line:0:1}" = "#" ] || [ -z "$line" ]; then
continue
fi
IFS=': ' read -r table_name query <<< "$line"
# Print the query to run.
echo "$table_name"
echo
echo sudo osqueryi --line \""$query limit 3"\"
echo
# Run the query ('2>&1' sends stderr to stdout)
sudo osqueryi --line "$query limit 3" 2>&1
echo
echo "---"
echo
done