1

Target(switch):
Cisco 2960-X running IOS version 15.2(2)E6

Host(server trying to reach the switch):
FreeBSD 11.0-RELEASE

I want to save the learned MAC addresses from the switch periodically to maintain a "who was where and when" database of the client devices.

I know of the SNMP approach (where different MIBs are read and correlated) but due to reasons I would like not to discuss here I cannot use SNMP.

My solution is to save a public-ssh key on the switch and issue the following command:

ssh user@switch "show mac address-table" > outputfile.txt

Generally the command works and the output of the "sh mac add" will be redirected to the outputfile. BUT:

About 20% of the tries I end up with an 8kb (exactly 8kb) file as the output, the rest is truncated somehow, right in the middle of the output.

Does someone know why my files get truncated?

UPDATE1:
I forgot to mention that the ssh command is in a bash script that is run by cron every X minutes. To be exact 2 commands are now in the script for 2 different switches and the anomaly is not restricted to the second switch - both of them return sometimes 8k results.

UPDATE2:
If I alter the script to execute the 2 ssh commands in a loop and call it directly from my shell the problem seems to disappear... (Originally the script was called by cron) My conclusion is that it has something to do with cron.

4
  • 2
    So, why again can't you use SNMP?
    – EEAA
    Jun 16, 2017 at 17:42
  • Let's say its not an option right now. The only access I have to the switches is SSH/SCP due to restrictions.
    – TeBe
    Jun 16, 2017 at 20:27
  • I completely understand (I wouldn't myself). Anyway, theere's no way this doesn't have something to do with stdio buffering on that ssh connection - that 8k is too neat. This can be one of those times to actually use cat: ssh ... | cat -u > outpufile.txt Jun 16, 2017 at 20:42
  • I tried the cat -u option, but results are the same. What I forgot to mention that the command is in a bash script (nothing else just the command for 2 switches for now) and the script runs from cron. I will add that to the question.
    – TeBe
    Jun 16, 2017 at 22:02

1 Answer 1

1

I had exactly the same issue, after about 64.000 byte the output got cut - but only when running it via cron. After troubleshooting I found the following solution

ssh user@switch "show mac address-table"

replace by

ssh user@switch < echo "show mac address-table"

Please dont ask my why the solution works....

1
  • If you can't explain, do you have a source to cite? Jul 14, 2017 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .