
if [ "$#" -ne 2 ]; then
    echo "Usage: copy_pnp_logs.sh <apic_ipaddr> <password>"
    exit 1
fi
echo $#

export GRAPEVINE_IP=$1
export GRAPEVINE_PASS=$2
#export GRAPEVINE_IP='172.19.190.15'
#export GRAPEVINE_PASS='Cisco123'

#Gets the pnp-service vm ip
export pnp_service_vm_ip=$(sshpass -p $GRAPEVINE_PASS ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -t  grapevine@$GRAPEVINE_IP /opt/cisco/grapevine/bin/grape instance display|grep -B2 pnp-service|grep ip|cut -d , -f 2| cut -d : -f 2)

#cmd_to_copy_pnp_server_log_to_grapevine_vm
sshpass -p $GRAPEVINE_PASS ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null grapevine@$GRAPEVINE_IP scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $pnp_service_vm_ip:/var/log/grapevine/services/pnp-service*/*/*.log* .


#cmd_to_copy_pnp_server_log_from_grapevine_vm_to_local
sshpass -p $GRAPEVINE_PASS scp -r -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null grapevine@$GRAPEVINE_IP:~/*.log* .

#cmd_to_delete_pnp_server_log_from_grapevine_vm
sshpass -p $GRAPEVINE_PASS ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null grapevine@$GRAPEVINE_IP 'rm pnp*.log*'
