From a5bf22a8e8f12358c1295847aca46cc596a1a196 Mon Sep 17 00:00:00 2001 From: Mark McDonnell Date: Tue, 22 Mar 2016 18:06:24 +0000 Subject: [PATCH] Update scp-remote-to-local.sh --- scp-remote-to-local.sh | 45 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/scp-remote-to-local.sh b/scp-remote-to-local.sh index 11d18d3..0a3ca0c 100644 --- a/scp-remote-to-local.sh +++ b/scp-remote-to-local.sh @@ -7,7 +7,7 @@ # /bin/bash ./results.sh # # Description: -# Grabs list of running instances for specified BBC Cosmos component (TEST environment) +# Grabs list of running instances for specified Cosmos component (TEST environment) # SCP's known log locations from remote to new local directory # Enable a form of 'strict mode' for Bash @@ -18,7 +18,7 @@ IFS=$'\n\t' cert=${1:-} component=${2:-} user=${3:-} -api="https://api.live.bbc.co.uk/cosmos/env/test/component/$component/instances" +api="https://api.live.bbc.co.uk/cosmos/env/test/component/$component" if [ "$#" -ne 3 ]; then cat < , + +for ((n = 0; n < $data_len; n++)) do - scp -v -r "$user@$ip,eu-west-1:/var/log/component/app.log" "./$logdir/$ip.log" & + ssh_success=false + valid="current" + + id=$(($n * 2)) + ip=$(($id + 1)) + + instance_id=${data[$id]} + instance_ip=${data[$ip]} + + response=$(curl --silent \ + --cert $cert \ + --header "Content-Type: application/json" \ + --request POST \ + --data "{\"instance_id\":\"$instance_id\"}" \ + "$api/logins/create") + + checkpoint_id=$(echo $response | jq --raw-output .url | cut -d '/' -f 7) + + until $ssh_success + do + status=$(curl --silent --cert $cert "$api/login/$checkpoint_id" | jq --raw-output .status) + + if [ "$status" = "$valid" ]; then + ssh_success=true + printf "\n" + echo "OK we've got SSH access to instance number $(($n + 1)): $instance_id ($instance_ip)" + printf "\n" + else + echo "Sorry, still waiting access to: $instance_id (status == $status)" + fi + done + + scp -r "$user@$instance_ip,eu-west-1:/var/log/component/app.log" "./$logdir/$instance_ip.log" & done wait