#!/bin/bash

if [[ -z $1 ]]
then
    # echo -n 0
    exit 1
fi

HOST="$1"
USER="username"
TIMEOUT=10s
export SSHPASS="password"

CMD="show platform tcam utilization ucastv4 0 | i UCASTV4"
RAW_OUTPUT_USED=`timeout $TIMEOUT sshpass -e ssh -q -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oBatchMode=no $USER@$HOST $CMD 2>/dev/null`
# This output sometimes ends in a carriage return character
UCASTV4_USED=`echo -n $RAW_OUTPUT_USED | awk '{print $NF}' | tr -d "\r"`

CMD="show platform aspdma template | i NILE_NUM_IPV4_ROUTES"
RAW_OUTPUT_TOTAL=`timeout $TIMEOUT sshpass -e ssh -q -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oBatchMode=no $USER@$HOST $CMD 2>/dev/null`
# This output sometimes ends in a carriage return character
UCASTV4_TOTAL=`echo -n $RAW_OUTPUT_TOTAL | awk '{print $NF}' | tr -d "\r"`

# Must remove new line from output for Cacti
echo -n "ucastv4_used:$UCASTV4_USED ucastv4_total:$UCASTV4_TOTAL"

