#!/bin/bash # # This is a simple tool that monitors a directory and moves files into other # dirs in a round robin fashion. # # $Id: //guest/cmclouth/projects/htd-deployment/htd-source/tools/ingestprocessmgr2.sh#3 $ # sleeptime=30 # time, in seconds, to wait before checking for files lastmodtime=1 # time, in minutes, that a file must be older than set -e # Exit immediately on non-zero status. if [ $# -lt 3 ]; then echo "Usage: $0 <Path/to/auditconverter2.py> <Path/to/archive/dir> </Path/to/monitor/dir> <filepatern> </Path/to/target1> [</Path/to/target2> ...]" echo "Example: $0 /home/interset/tools/auditconverter2.py /tmp/ingested/ /tmp/ingest-all *.gz /tmp/ingest-test1" exit 1 fi # validate audit converter if [ ! -e $1 ]; then echo "auditconverter doesn't exist: $1 doesn't exist" exit 1 fi # validate archive dir if [ ! -d $2 ]; then echo "archive directory: $2 doesn't exist" exit 1 fi # validate source dir if [ ! -d $3 ]; then echo "source directory: $3 doesn't exist" exit 1 fi AUDITCONVERTER="$1" archivedir="$2" sourcedir="$3" filepattern="$4" # validate target dirs declare -a targetdirs targetcount=0 for arg in "${@:5}"; do targetdirs[targetcount]=$arg if [ ! -d ${targetdirs[targetcount]} ]; then echo "target directory: ${targetdirs[targetcount]} doesn't exist" exit 1 fi ((targetcount += 1)) done offset=0 echo "AUDITCONVERTER=$AUDITCONVERTER" echo "archivedir=$archivedir" echo "sourcedir=$sourcedir" echo "filepattern=$filepattern" echo "targetdirs=${targetdirs[@]}" while true; do nonefound="" echo "scanning directory: $sourcedir" for sourcefile in $(find "$sourcedir" -maxdepth 1 -path "$filepattern" -mmin +$lastmodtime); do if [ $offset -ge $targetcount ]; then offset=0 fi # echo $(dirname "$sourcefile")/$(date +%Y-%m-%d-%H-%M-%S-%N-)$(basename "$sourcefile") newname=$(dirname "$sourcefile")/$(date +%Y-%m-%d-%H-%M-%S-%N-)$(basename "$sourcefile") echo "rename source file: $sourcefile to $newname" mv "$sourcefile" "$newname" echo "processing source file: $newname to target directory: ${targetdirs[offset]}" python3 "$AUDITCONVERTER" -c -i "$newname" -o "${targetdirs[offset]}" 2> /dev/null echo "archive source file $newname to $archivedir" mv "$newname" "$archivedir" nonefound="true" ((offset += 1)) done if [ -z "$nonefound" ]; then echo "No files found; sleep for $sleeptime" sleep $sleeptime fi done exit 1
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 18159 | Charlie McLouth |
Two changes: * Allow ingested directory (already processed) to be a configuration option * To prevent the overwriting of existing files, we will first brand all incoming files with a date and time. |
||
#2 | 18158 | Charlie McLouth | Changed filetype to ktext | ||
#1 | 18157 | Charlie McLouth | Merging changes |