-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrps
More file actions
executable file
·93 lines (71 loc) · 1.42 KB
/
Copy pathrps
File metadata and controls
executable file
·93 lines (71 loc) · 1.42 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
90
91
92
93
#!/usr/bin/env bash
# Time-stamp: <2017-09-13 10:59:43 Wednesday by ahei>
# @file ps.sh
# @version 1.0
# @author ahei
readonly PROGRAM_NAME="rps"
readonly PROGRAM_VERSION="1.0.0"
home=`cd $(dirname "$0") && pwd`
version()
{
echo "${PROGRAM_NAME} ${PROGRAM_VERSION}"
exit 1
}
# echo to stderr
echoe()
{
printf "$*\n" 1>&2
}
usage()
{
local code=1
local redirect
if [ $# -gt 0 ]; then
code="$1"
fi
if [ "$code" != 0 ]; then
redirect="1>&2"
fi
eval cat "$redirect" << EOF
usage: ${PROGRAM_NAME} [OPTIONS] CLUSTER PATTERN [PS_OPTIONS]
Options:
-o REMOTE_OPTIONS
Set remote's options.
-v Output version info.
-h Output this help.
EOF
exit "$code"
}
optInd=1
while getopts ":hvo:" OPT; do
case "$OPT" in
o)
remoteOptions="$OPTARG"
;;
v)
version
;;
h)
usage 0
;;
:)
case "${OPTARG}" in
?)
echoe "Option \`-${OPTARG}' need argument.\n"
usage
esac
;;
?)
echoe "Invalid option \`-${OPTARG}'.\n"
usage
;;
esac
done
shift $((optInd - 1))
if [ $# -lt 2 ]; then
usage
fi
cluster=$1
pattern=$2
shift 2
remote -q $remoteOptions "$cluster" "ps -ef $@ | fgrep '$pattern' | fgrep -v grep" | fgrep -v "$PROGRAM_NAME"