From ca1228c1f38a2b81527d4401e1a6dc6f09c7a2ba Mon Sep 17 00:00:00 2001 From: Andrea Giovine Date: Mon, 17 Aug 2020 17:17:48 +0200 Subject: create script to feed Caronte --- scripts/feedCaronte.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 scripts/feedCaronte.sh diff --git a/scripts/feedCaronte.sh b/scripts/feedCaronte.sh new file mode 100755 index 0000000..daf8577 --- /dev/null +++ b/scripts/feedCaronte.sh @@ -0,0 +1,52 @@ +#!/bin/bash - +#=============================================================================== +# +# FILE: feedCaronte.sh +# +# USAGE: ./feedCaronte.sh PCAP_DIR_PATH +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: inotify-tools, curl +# BUGS: --- +# NOTES: test in Debian Buster +# AUTHOR: Andrea Giovine (AG), +# ORGANIZATION: +# CREATED: 17/08/2020 16:36:57 +# REVISION: --- +#=============================================================================== + +set -o nounset # Treat unset variables as an error + +CHECK_INOTIFY=$(dpkg-query -W -f='${status}' 'inotify-tools') + +if [[ "$CHECK_INOTIFY" != 'install ok installed' ]]; then + echo "Install inotify-tools" + exit 1 +fi + +CHECK_CURL=$(dpkg-query -W -f='${Status}' 'curl') + +if [[ "$CHECK_CURL" != 'install ok installed' ]]; then + echo "Install curl" + exit 1 +fi + +if [[ "$#" -ne 1 ]]; then + echo "Need 1 arg" + exit 2 +fi + +PCAP_DIR="$1" + +if [[ -z "$PCAP_DIR" ]]; then + echo "Need path to dir where are store pcaps" + exit 2 +fi + +inotifywait -m "$PCAP_DIR" -e create -e moved_to | + while read dir action file; do + echo "The file $file appeared in directory $dir via $action" + curl -F "file=@$file" "http://localhost:3333/api/pcap/upload" + done -- cgit v1.2.3-70-g09d2