diff options
author | Andrea Giovine | 2020-08-17 15:17:48 +0000 |
---|---|---|
committer | Andrea Giovine | 2020-08-17 15:17:48 +0000 |
commit | ca1228c1f38a2b81527d4401e1a6dc6f09c7a2ba (patch) | |
tree | e73f0cd03b5f5d7d7a62d31bc0a8f2c24a1cce92 /scripts | |
parent | fe511f33c451a4c1c85950d0619b927747757d4e (diff) |
create script to feed Caronte
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/feedCaronte.sh | 52 |
1 files changed, 52 insertions, 0 deletions
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 |