I am trying to get information from the command "show mac-address" out of a collection of 12 procurve switches in 2 different locations all connected via fiber PTP. I want to import this into SQL for some scheduled reporting of statistics, movement, routes, etc... I have managed to generate some very interesting and useful data that will eventually allow me to get this monster I inherited into less of the monster it is.
I have all components of this working other that the fact I have to manually go grab the data per switch using putty, save them in a directory where a scheduled task formats the dumps into csv, cleans them up, and imports them using BULK INSERT.
Now I want to automate retrieval of the data from the switches so I can focus on the data side, and stop spending so much time on the collection side.
I have tried PLINK, however there seems to be some sort of emulation issue where the data is interpreted as the incorrect format, and I get files full of gibberish.
using...
plink -batch -ssh -l <username> -pw <password> xxx.xxx.xxx.xxx < cmds.txt > out.txt
the switches are in stacks, so i have to get past the "not hp management" messages, and "what switch do you want to log into" prompts, this seems to work with just \n\n in the file (same as I would when I log into putty, enter twice) But past that I get long ASCII sequences that seems odd because everything up to that point sees to work without issue.
I have already accepts the key in putty, and again since I am getting all the login and stack commander messages, I am assuming all of this is working.
Any clues on how to either get this to work, or a reasonable alternative to achieve the same?
Example of what I am getting...
HP J9148A 2910al-48G-PoE Switch
Software revision W.15.13.0005
Copyright (C) 1991-2014 Hewlett-Packard Development Company, L.P.
RESTRICTED RIGHTS LEGEND
Confidential computer software. Valid license from HP required for possession,
use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer
Software, Computer Software Documentation, and Technical Data for Commercial
Items are licensed to the U.S. Government under vendor's standard commercial
license.
HEWLETT-PACKARD DEVELOPMENT COMPANY, L.P.
20555 State Highway 249, Houston, TX 77070
Non-HP transceiver detected, which may cause network problems.
Use 'show interface transceiver' command for details.
HP will not support or troubleshoot problems with these transceivers.
[1;15r[1;1H[24;1HPress any key to continue[15;1H[?25h[24;27H[2J[?7l[1;15r[?6l[24;27H[?25h[23;1H Stack Members
SN MAC Address System Name Device Type Status
-- ------------- ------------- -------------------- -------------------------
0 xxxxxx-xxxxxx Switch1 HP 2910al-48G-PoE Commander Up
1 xxxxxx-xxxxxx Switch2 HP 2910al-48G Member Up
2 xxxxxx-xxxxxx Switch3 HP 2910al-24G-PoE Member Up
[23;1HEnter switch number to connect to or <CR>:[23;1H[23;44H[?25h[23;1H[?25h[23;44H[?6l[1;24r[?7l[2J[1;1H[1920;1920H[6n[1;1HYour previous successful login (as manager) was on 2016-01-29 19:31:41
from xx.x.x.xxx
[1;24r[24;1H[24;1H[2K[24;1H[?25h[24;1H[24;1HSwitch1# [24;1H[24;11H[24;1H[?25h[24;11H[24;0HE[24;1H[24;11H[24;1H[2K[24;1H[?25h[24;1H[1;24r[24;1H[1;24r[24;1H[24;1H[2K[24;1H[?25h[24;1H[24;1HSwitch1# [24;1H[24;11H[24;1H[?25h[24;11H[24;0HE[24;1H[24;11H[24;1H[2K[24;1H[?25h[24;1H[1;24r[24;1H[1;24r[24;1H[24;1H[2K[24;1H[?25h[24;1H[24;1HSwitch1#
So I am getting so far as the Switch1# prompt at the switch console.
my input file is at the moment just
show mac-address
With two blank lines above to perform the two "any key" and to continue" requests.
Any help greatly appreciated.
Do you have to use putty from Windows? Coming from a Linux box, I would either do
or if that does not work, I'd use the program
expect
. In fact there is a version of expect for Windows that you could probably use instead of plink.Expect syntax example off the top of my head with varying switch output (should work with or without the "press any key", but of course I have tested nothing):
But do as Paul suggested and try out
autoexpect
, it will let you run through your script and will output the expect script that will do the same thing. Then you take that output and replace the name or IP of the switch with[lindex $argv 0]
, and execute it with the name of the switch as argument.I never did get this to work as expected, and I have not been back on the site in a long time, but since the question seemed to be popular, I decided to post what I ended up doing in the end.
I enabled telnet on the units, and used the following and NCAT to psudo script telnet style commands to it.
This allowed me to issue a copy command to TFTP and have the switches send the data back to me rather than try to parse it out of returned output. Of course I did not want to hard code passwords etc, and make it reusable for future needs. It got me through the issues I was having. :-)
switches.txt was just a list of the IP addresses, and I had to use NCAT 7.40 as versions past that have a bug that prevented it from working properly.
Now of course this is not as secure as the SSH method, in fact unless you know the traffic is not being intercepted I do not suggest it as it is easily sniffed (including credentials) but it was very functional. This can be somewhat lessened with a dedicated VLAN and a separate subnet dedicated just to automation. Thought it may help other trying to automate such tedious tasks. If nothing else I illustrates where there is a will and a sysadmin, there IS a solution even if it is a dirty one. Hope it helps someone else.