-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground
executable file
·48 lines (44 loc) · 1.61 KB
/
background
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
#!/bin/bash
# Get DTP and set containers to an array
POD="$(kubectl get pods | grep dtp | grep Running | awk '{print $1}')"
ARRAY=($(kubectl get pods ${POD} -o jsonpath='{.spec.containers[*].name}'))
POSSIBLE=(dtp-base dtp-gcp dtp-irods dtp-aws dtp-minio dtp-ndn dtp-aspera dtp-sra-toolkit dtp-globus)
POSITIONAL=()
while [[ $# -gt 0 ]]
do
KEY="$1"
case $KEY in
-h|--help)
echo "--------------------"
echo "- BACKGROUND MODE -"
echo "--------------------"
echo "Description: Background Mode is a way to pass commands to DTP containers without interactively entering the container."
echo "Usage: ./background <--container1> 'command1' <--container2> 'command2' .... <--containerN> 'commandN'"
echo "Possible: ${POSSIBLE[@]}"
echo "Running: ${ARRAY[@]}"
echo "--------------------"
shift # past argument
shift # past value
;;
--dtp-*)
CONTAINER=${KEY#"--"}
if [[ " ${ARRAY[*]} " == *" ${CONTAINER} "* ]]; then
echo "Executing $2 in ${CONTAINER}...."
kubectl exec -it ${POD} --container ${CONTAINER} -- $2
elif [[ " ${POSSIBLE[*]} " == *" ${CONTAINER} "* ]]; then
echo "Container ${CONTAINER} not found! Are you sure it is deployed?"
else
echo "Container ${CONTAINER} is not one of the possible options! Are you sure it is spelled correctly?"
echo "Possible: ${POSSIBLE[@]}"
fi
shift # past argument
shift # past value
;;
*) # unknown option
echo "Unknown option: $1"
echo "Use -h/--help for assistance."
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters