-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscancel.sh
More file actions
executable file
·99 lines (83 loc) · 2.37 KB
/
Copy pathscancel.sh
File metadata and controls
executable file
·99 lines (83 loc) · 2.37 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
94
95
96
97
98
99
#!/bin/bash
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
source "$script_dir/cluster_helpers.sh"
CLUSTER="${SCANCEL_CLUSTER:-bluehive3}"
SCANCEL_ARGS=()
SSH_LOCALE_ENV=(LC_ALL=C LANG=C LC_CTYPE=C)
usage() {
cat <<EOF
Usage: $(basename "$0") [wrapper-options] [--] [scancel-options] [job_id ...]
Wrapper options:
-a, --cluster CLUSTER SSH cluster to run scancel on
--remote-cluster CLUSTER Same as --cluster, avoids scancel option clashes
--wrapper-help Show this help
All other arguments are forwarded unchanged to remote scancel.
Use -- when a scancel argument conflicts with a wrapper option.
EOF
}
set_cluster() {
if ! require_cluster "$1"; then
exit 1
fi
CLUSTER="$1"
}
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--wrapper-help)
usage
exit 0
;;
-a|--cluster|--remote-cluster)
if [[ $# -lt 2 || -z "$2" ]]; then
echo "Error: $1 requires a cluster name" >&2
exit 1
fi
set_cluster "$2"
shift 2
;;
--cluster=*|--remote-cluster=*)
set_cluster "${1#*=}"
shift
;;
--)
shift
break
;;
*)
break
;;
esac
done
SCANCEL_ARGS=("$@")
}
shell_quote() {
local value="$1"
value=${value//\'/\'\\\'\'}
printf "'%s'" "$value"
}
build_remote_command() {
local remote_command=""
local arg
for arg in scancel "$@"; do
if [[ -n "$remote_command" ]]; then
remote_command+=" "
fi
remote_command+="$(shell_quote "$arg")"
done
printf "%s" "$remote_command"
}
main() {
local remote_command
local login_command
parse_args "$@"
# shellcheck disable=SC1090
source "$script_dir/start_ssh_control.sh" -a "$CLUSTER" || exit $?
remote_command="$(build_remote_command "${SCANCEL_ARGS[@]}")"
login_command="LC_ALL=C LANG=C LC_CTYPE=C bash -lc $(shell_quote "$remote_command")"
exec env "${SSH_LOCALE_ENV[@]}" ssh -F /dev/null \
-o "ControlPath=$SSH_CONTROL_PATH" -T "$SSH_LOGIN_TARGET" "$login_command"
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi