0
0
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:
Mark McDonnell 2016-03-23 16:03:59 +00:00
parent 944677eea5
commit 1cd3b79c1d

View File

@ -18,6 +18,7 @@ IFS=$'\n\t'
cert=${1:-} cert=${1:-}
component=${2:-} component=${2:-}
user=${3:-} user=${3:-}
failed_access=()
api="https://api.live.bbc.co.uk/cosmos/env/test/component/$component" api="https://api.live.bbc.co.uk/cosmos/env/test/component/$component"
if [ "$#" -ne 3 ]; then if [ "$#" -ne 3 ]; then
@ -33,6 +34,10 @@ If you have any curl/cert issues try:
If you have any parsing issues try: If you have any parsing issues try:
brew install jq brew install jq
If you have any issues with SCP then
make sure you've given your user SSH access via Cosmos.
This is something I'd like to automate via this script in future.
EOF EOF
exit 1 exit 1
@ -46,7 +51,7 @@ data_len=$((${#data[@]} / 3)) # we know we'll always have a triad of data -> <id
for ((n = 0; n < $data_len; n++)) for ((n = 0; n < $data_len; n++))
do do
ssh_success=false ssh_success=false
valid="current" failed=false
# parse array indexes needed to extract data # parse array indexes needed to extract data
id=$(($n * 3)) id=$(($n * 3))
@ -75,17 +80,25 @@ do
do do
status=$(curl --silent --cert $cert "$api/login/$checkpoint_id" | jq --raw-output .status) status=$(curl --silent --cert $cert "$api/login/$checkpoint_id" | jq --raw-output .status)
if [ "$status" = "$valid" ]; then if [ "$status" = "current" ]; then
ssh_success=true ssh_success=true
printf "\n" printf "\n"
echo "ssh access granted for instance $(($n + 1)): $instance_id ($instance_ip)" echo "ssh access granted for instance $(($n + 1)): $instance_id ($instance_ip)"
printf "\n" printf "\n"
elif [ "$status" = "failed" ]; then
failed_access+=($instance_id $instance_ip $launch_time)
failed=true
break
else else
echo -ne "status == $status "\\r echo -ne "status == $status "\\r
fi fi
done done
if [ "$failed" = true ]; then
continue
else
scp -r "$user@$instance_ip,eu-west-1:/var/log/component/app.log" "./$logdir/$launch_time-$instance_ip.log" scp -r "$user@$instance_ip,eu-west-1:/var/log/component/app.log" "./$logdir/$launch_time-$instance_ip.log"
fi
done done
# removed 'wait' command here and '&' backgrounding of scp process # removed 'wait' command here and '&' backgrounding of scp process
@ -93,3 +106,14 @@ done
printf "\n######################################\n\n" printf "\n######################################\n\n"
echo "all logs copied successfully" echo "all logs copied successfully"
failed_len=$(echo ${#failed_access[@]})
if [ "$failed_len" -gt 0 ]; then
printf "\n######################################\n\n"
echo "there were '$failed_len' failed ssh attempts"
for i in "${failed_access[@]}"
do
printf "\t - $i\n"
done
fi