As part of my job I may need to access the GUI of a Cisco phone (Cisco 8851, 7960, etc.) to determine what MAC address is assigned to the device. The MAC address is prefixed with SEP (e.g. SEPAABBCCDDEEFF) as the syslogs provided by the call processing server, on specific events, only includes the IP address, not the MAC address. MAC address is needed to confirm if a given set of configurations exist for that device on the server. Manually pulling up a chunk of 50-100 phones to check MAC addresses via http is awful. I tried to automate this, and sort of did, but I missed the mark in Python3 and crapped out entirely on Python2, won't run past user input collection.
My questions:
1) General question regarding awk and/or similar tools -- to check the data returned from the website for the necessary SEP* string I use awk to print out multiple instances of SEP* that exist on the same line, but it provides two outputs rather than just the first. I've tried using "grep -o "SEP*" but this provides only SEP as the response. Thoughts on how I can have this return the first instance of SEP* (e.g. SEPAABBCCDDEEFF) only, instead of an entire line of html code?
Issue #1 - As you can see the awk attempt does provide the first instance cleanly but the second instance it provides a lengthy bit of garbage on both ends. My intention was to only provide a single SEP* value per web link it parses.
@ubuntu:~/Scripts/CiscoScripts$ python transientPhones.py
How many phones?: 1
What is the phone IP address?: <ip-addr>
SEPAABBCCDDEEFF
width=20></TD><TD><B>SEPAABBCCDDEEFF</B></TD></TR><TR><TD><B>
kenneth@ubuntu:~/Scripts/CiscoScripts$
2) Running the script in a Python 2.7 environment, the script fails on SyntaxError: invalid syntax after collection of the user input. I am failing to understand why (beyond I'm doing it wrong or in an incompatible way). My home environment is python 3.x (latest) and I did not take that into consideration when working up scripts to use in a python 2.7 environment, and as I am new to python and coding I have really only been learning python3 syntax and conventions. Any thoughts here?
Issue #2 -- This one has me confused. I'm sure there's a simple answer/solution here... I'm not experienced enough to see it.
$:python transientPhones.py
How many phones?: 1
What is the phone IP address?: 192.168.1.1
Traceback (most recent call last):
File "transientPhones.py", line 13, in <module>
ipAddress.append(input('What is the phone IP address?: '))
File "<string>", line 1
192.168.1.1
^
SyntaxError: invalid syntax
Code:
#!/usr/bin/python
#import required modules
import subprocess
#Define Variables
x = input('How many phones?: ')
x = int(x)
ipAddress = []
#Loop to grab IP addresses
for i in range(x) : #Loop X amount of times based on input from user
ipAddress.append(input('What is the phone IP address?: '))
#Grab XML Data and awk it for SEP*.
for n in ipAddress :
subprocess.call ("curl --max-time 5 -s http://" + n + "/CGI/Java/Serviceability?adapter=device.statistics.device | awk '/SEP*/{for(i=1;i<=NF;++i)if($i~/SEP*/)print $i}'", shell=True)