Skip to content

Commit 1deecac

Browse files
committed
Improve timing outputs
1 parent 572862d commit 1deecac

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

ssh-oci-bastion.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33
set -o pipefail
44

5-
readonly VER=2.1.2
5+
readonly VER=2.1.3
66

77
# Remove the longest `*/` prefix
88
readonly SCRIPT_NAME_WITH_EXT="${0##*/}"
@@ -150,10 +150,14 @@ if [[ $port ]]; then
150150
# `--ssh-public-key-file` is required
151151
# `--target-private-ip` "${OCI_INSTANCE}"
152152
# shellcheck disable=SC2086 # $PROFILE_OPT is a two-word CLI option
153-
session_ocid=$(time oci bastion session create-port-forwarding $PROFILE_OPT --bastion-id "$OCI_BASTION_OCID" \
154-
--target-resource-id "$OCI_INSTANCE_OCID" --target-port "$port" \
155-
--session-ttl $MAX_TTL --ssh-public-key-file $SSH_PUB_KEY --wait-for-state SUCCEEDED --wait-for-state FAILED \
156-
--wait-interval-seconds $CHECK_INTERVAL_SEC | jq --raw-output '.data.resources[0].identifier')
153+
session_ocid=$(time ( # `time` prints to stderr so it does not interfere with the pipe
154+
oci bastion session create-port-forwarding $PROFILE_OPT --bastion-id "$OCI_BASTION_OCID" \
155+
--target-resource-id "$OCI_INSTANCE_OCID" --target-port "$port" --session-ttl $MAX_TTL \
156+
--ssh-public-key-file $SSH_PUB_KEY --wait-for-state SUCCEEDED --wait-for-state FAILED \
157+
--wait-interval-seconds $CHECK_INTERVAL_SEC | jq --raw-output '.data.resources[0].identifier';
158+
>&2 printf "It took:"
159+
)
160+
)
157161
echo "Created the bastion port forwarding session: $session_ocid"
158162

159163
# shellcheck disable=SC2086 # $PROFILE_OPT is a two-word CLI option
@@ -183,10 +187,14 @@ if [[ $HOST_USER ]]; then
183187
# `--wait-interval-seconds`: state check interval (defaults to 30 seconds).
184188
# `--ssh-public-key-file` is required
185189
# shellcheck disable=SC2086 # $PROFILE_OPT is a two-word CLI option
186-
session_ocid=$(time oci bastion session create-managed-ssh $PROFILE_OPT --bastion-id "$OCI_BASTION_OCID" \
187-
--target-resource-id "$OCI_INSTANCE_OCID" --target-os-username "$HOST_USER" --session-ttl $MAX_TTL \
188-
--ssh-public-key-file $SSH_PUB_KEY --wait-for-state SUCCEEDED --wait-for-state FAILED \
189-
--wait-interval-seconds $CHECK_INTERVAL_SEC | jq --raw-output '.data.resources[0].identifier')
190+
session_ocid=$(time ( # `time` prints to stderr so it does not interfere with the pipe
191+
oci bastion session create-managed-ssh $PROFILE_OPT --bastion-id "$OCI_BASTION_OCID" \
192+
--target-resource-id "$OCI_INSTANCE_OCID" --target-os-username "$HOST_USER" --session-ttl $MAX_TTL \
193+
--ssh-public-key-file $SSH_PUB_KEY --wait-for-state SUCCEEDED --wait-for-state FAILED \
194+
--wait-interval-seconds $CHECK_INTERVAL_SEC | jq --raw-output '.data.resources[0].identifier';
195+
>&2 printf "It took:"
196+
)
197+
)
190198
echo "Created the bastion session: $session_ocid"
191199

192200
# shellcheck disable=SC2086 # $PROFILE_OPT is a two-word CLI option

0 commit comments

Comments
 (0)