forked from cmccabe/cmccabe-hbin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rmjar.sh
executable file
·45 lines (37 loc) · 953 Bytes
/
rmjar.sh
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
#!/bin/bash
die() {
echo $@
exit 1
}
usage() {
cat <<EOF
rmjar.sh: remove jars whose name matches a pattern
usage: rmjar.sh [options] [param]
options:
-h: this help message
param values:
all: remove all jars
cdh4: remove all jars except for cdh4 jars
apache3: remove all jars except for apache 3.0.0 jars
EOF
}
while getopts "Aa:c:h" flag; do
case $flag in
h) usage; exit 0;;
*) echo; usage; exit 1;;
esac
done
shift $(($OPTIND - 1))
[ $# = 1 ] || die "must give exactly one argument. -h for help."
ARG=$1
case $ARG in
all) find -name '*.jar' | xargs rm -f;;
apache3) find -name '*.jar' | egrep '[^A-Za-z]3.0.0-SNAPSHOT[^A-Za-z]' \
| xargs -l rm -f
find -name '*.jar' | egrep '[^A-Za-z]cdh4[^A-Za-z]' \
| xargs -l rm -f;;
cdh4) find -name '*.jar' | egrep -v '[^A-Za-z]cdh4[^A-Za-z]' \
| xargs -l rm -f;;
*) die "don't know how to handle $ARG. -h for help.";;
esac
exit 0