#!/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/ingestprocessmgr.sh#4 $ # 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/monitor/dir> <filepatern> </Path/to/target1> [</Path/to/target2> ...]" echo "Example: $0 /tmp/ingest-all *.gz /tmp/ingest-test1" exit 1 fi # validate source dir if [ ! -d $1 ]; then echo "source directory: $1 doesn't exist" exit 1 fi sourcedir="$1" filepattern="$2" # validate target dirs declare -a targetdirs targetcount=0 for arg in "${@:3}"; 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 "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 "moving source file: $newname to target directory: ${targetdirs[offset]}" mv "$newname" "${targetdirs[offset]}" nonefound="true" ((offset += 1)) done if [ -z "$nonefound" ]; then echo "No files found; sleep for $sleeptime" fi sleep $sleeptime done exit 1
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 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. |
||
#3 | 18158 | Charlie McLouth | Changed filetype to ktext | ||
#2 | 18132 | Charlie McLouth | Adding tools for handing ingest configuration and job management | ||
#1 | 18131 | Charlie McLouth | Moving files | ||
//guest/cmclouth/projects/htd-deployment/htd-source/tools/ingestmgr.sh | |||||
#2 | 18130 | Charlie McLouth | add file pattern as commandline arg | ||
#1 | 18129 | Charlie McLouth | A simple tool to watch a directory and move files to others. |