Since frequent snmp queries against the nexus can be problematic, I have gone a different route to get the data I need.
I have developed a simple script that gathers interface statistics from two Nexus 9372 and then sums the numbers to give closer to realtime aggregate stats on a port channel.
Im running it in the guestshell environment.
Part of my script does a simple dohost to get some information from a CLI show command.....
The portion of my script where I call the "dohost" is below..
inputget="$(dohost "sh int e101/1/47 | grep '30 seconds input rate'")"
outputget="$(dohost "sh int e101/1/47 | grep '30 seconds output rate'")"
inputn1="$(awk '{print $5}' <<< "$inputget")"
outputn1="$(awk '{print $5}' <<< "$outputget")"
The script works fine when I run it from a guestshell session, and works fine if I background it (&) FROM a guestshell session.
The problem arises when I try to either run the script as a service or try to call the script from CLI with a "run guestshell
What I have determined is that the builtin python script for "dohost" calls itself with a sudo, and If I try to run as a service or call from the CLI to background, there is not an associated "tty" thus is fails...
Here is the guts of "dohost"
[guestshell@guestshell ~]$ cd /usr/bin
[guestshell@guestshell bin]$ more dohost
#!/bin/bash
#
# Unpublished Work Copyright (c) 2014, 2015 by Cisco Systems, Inc.
# All Right reserved.
#
exec sudo -E python /usr/lib64/python2.7/site-packages/cisco/dohost.pyc "$@"
[guestshell@guestshell bin]$
Here is the output of the failed condition below:
Nx9k-1# run guestshell ./nex1calc.sh &
Nx9k-1# Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: sorry, you must have a tty to run sudo <<<<<------------------HERE IS THE PROBLEM----------------------
sudo: sorry, you must have a tty to run sudo <<<<<-------------------HERE IS THE PROBLEM----------------------
SNMPv2-SMI::enterprises.2112.1.4 = INTEGER: 0 <-----consequently I dont get part of my data to evaluate later in the script...
SNMPv2-SMI::enterprises.2112.1.1 = INTEGER: 0
this is totalbitsin 38825664
this is totalbitsout 30501600
SNMPv2-SMI::enterprises.2112.1.3 = INTEGER: 30501600
SNMPv2-SMI::enterprises.2112.1.6 = INTEGER: 38825664
sudo: sorry, you must have a tty to run sudo
sudo: sorry, you must have a tty to run sudo
SNMPv2-SMI::enterprises.2112.1.4 = INTEGER: 0
Can anyone shed some light on how I can get around this caveat ?
Thank you in advance!