-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkail-wrapper
More file actions
executable file
·90 lines (79 loc) · 1.63 KB
/
kail-wrapper
File metadata and controls
executable file
·90 lines (79 loc) · 1.63 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -o errexit -o pipefail -o nounset
! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
echo "`getopt --test` failed in this environment."
exit 1
fi
OPTIONS=haso:
LONGOPTS=help,append,stdout,out:
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
exit 2
fi
eval set -- "$PARSED"
help() {
echo "$0 [-a|--append] [-s|--stdout] [-o|--out outFile] -- [kail options]"
}
if [ "$#" -eq 1 ]; then
help
exit 0
fi
bin=kail
append=
stdout=
out=
while true; do
case "$1" in
-h|--help)
help
exit 0
;;
-a|--append)
append=y
shift
;;
-s|--stdout)
stdout=y
shift
;;
-o|--output)
out="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "arguments error"
exit 3
;;
esac
done
if [ -n "$out" ]; then
# create out dir if not exist
mkdir -p $(dirname "$out")
if [ -n "$append" ]; then
if [ -n "$stdout" ]; then
$bin "$@" |tee -a "$out"
else
$bin "$@" >> "$out"
fi
else
# backup original file
if [ -f "$out" ]; then
cp "$out" "$out.$(date +%s)"
fi
if [ -n "$stdout" ]; then
$bin "$@" |tee "$out"
else
$bin "$@" > "$out"
fi
fi
elif [ -n "$stdout" ]; then
$bin "$@"
else
echo "Either stdout or out file should be specified."
exit 0
fi