-
Notifications
You must be signed in to change notification settings - Fork 0
/
logpipe
executable file
·69 lines (59 loc) · 1.71 KB
/
logpipe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Logpipe is a utility for managing a batch processing pipeline.
#
# With repeated execution via cron, files flow through the following 4-stages:
#
# stage1-incoming - incoming raw files
# stage2-holding - candidates awaiting validation for stage3
# stage3-processing - raw files awaiting processing
# stage4-outgoing - cooked files awaiting transport to S3
#
# Actions executed in the processing stage can be written in any language and
# are executed using GNU parallel.
#
# The final stage of the pipeline uploads the processed output to Amazon S3 via
# s3cmd.
#
# Logpipe is written in Bash and makes use of non-portable shell features.
#
# Josh Enders <[email protected]>
# Enable null globbing behavior. When unset, glob pattern * falls back to
# literal '*' if no match, instead of an empty string
#
# Shell options cannot be exported and must be redefined in any subshells
# (excluding sourced shell fragments)
shopt -s nullglob
# Defined during installation
export LIB_PATH='__LIB_PATH__'
# Set as readonly
readonly LIB_PATH
source "${LIB_PATH}/environment.sh"
source "${LIB_PATH}/functions.sh"
# Export functions to child shells (mainly used by process substitution)
for func in $(declare -f | awk '/^[a-z] \ \(\)/ { print $1 }'); do
export -f "${func}"
done
unset func
function main() {
if [[ "$#" != 1 ]]; then
exit_with_usage
fi
case "$1" in
-m|--move)
get_glob "${STAGE1}"
move
;;
-p|--process)
get_glob "${STAGE3}"
process
;;
-u|--upload)
get_glob "${STAGE4}"
upload
;;
*)
exit_with_usage
;;
esac
}
main "$@"