mirror of
https://github.com/letic/Shell-Scripts.git
synced 2024-09-28 05:56:04 +00:00
Update scp-remote-to-local.sh
This commit is contained in:
parent
d5a969a24d
commit
a5bf22a8e8
@ -7,7 +7,7 @@
|
|||||||
# /bin/bash ./results.sh <cert_path> <component_name> <cosmos_user>
|
# /bin/bash ./results.sh <cert_path> <component_name> <cosmos_user>
|
||||||
#
|
#
|
||||||
# Description:
|
# 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
|
# SCP's known log locations from remote to new local directory
|
||||||
|
|
||||||
# Enable a form of 'strict mode' for Bash
|
# Enable a form of 'strict mode' for Bash
|
||||||
@ -18,7 +18,7 @@ IFS=$'\n\t'
|
|||||||
cert=${1:-}
|
cert=${1:-}
|
||||||
component=${2:-}
|
component=${2:-}
|
||||||
user=${3:-}
|
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
|
if [ "$#" -ne 3 ]; then
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@ -42,13 +42,46 @@ EOF
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
instances=($(curl --silent --insecure --cert $cert $api | jq --raw-output .[].private_ip_address))
|
|
||||||
|
|
||||||
logdir=$(mktemp -d logs.XXXX)
|
logdir=$(mktemp -d logs.XXXX)
|
||||||
|
|
||||||
for ip in "${instances[@]}"
|
data=($(curl --silent --cert $cert "$api/instances" | jq --raw-output ".[] | .id,.private_ip_address"))
|
||||||
|
data_len=$((${#data[@]} / 2)) # we know we'll always have a pair of data -> <id>,<ip>
|
||||||
|
|
||||||
|
for ((n = 0; n < $data_len; n++))
|
||||||
do
|
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
|
done
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
Loading…
Reference in New Issue
Block a user