Skip to content
Advertisement

Getting Output from Cisco C40 via Bash

Background

We have a handful of Cisco C40s that I’m trying to automate via bash (although I’d be open to alternatives). I need to log into it, dial an IP, get back the call ID that’s returned, and then use that CallID to send a DTMF tone to the far end. I’m able to get about 90% of the way there but for some reason using SSH isn’t returning all the text that’s returned when using an interactive session.

Interactive Shell Sample:

JavaScript

Non-Interactive Shell Samples

Without ssh -T or ssh -t -t Options

This occurs where call-init-step1.txt contains the xConfiguration Audio Volume: 0 and xCommand Dial Number: FAR_END_IP in addition to a bye to hang up.

JavaScript

What I’m missing here is the block with

JavaScript

so that I can parse it for the CallID and then use it to send the next commands.

With ssh -T or ssh -t -t Options

A few threads had suggested using ssh -T or ssh -t -t which in this case doesn’t seem to help, below is the output.

JavaScript

And

JavaScript

The Question

Any insight in how to get the missing DialResult block would be greatly appreciated.

Edit: I should also mention that ultimately the command cat call-init-step1.txt | ssh admin@cisco_codec would get redirected to a file to be parsed further on in my script meaning it would probably look something like cat call-init-step1.txt | ssh -t -t admin@cisco_codec > results.txt and then be parsed.

Edit 2: To frame what I’m working with the full API guide is found here

Edit 2.5: An attempt with expect

Per a suggestion from @MarkSetchell we went ahead and wrote a semi-functional expect script that looks like the following:

JavaScript

That resulted in the following:

JavaScript

Advertisement

Answer

It seemed there were a few approaches to this, if I had to stay with bash it seemed that using a properly written except script was going to be the way to go. That said someone on a Reddit post I’d made suggested XML. Using XML had crossed my mind but neither I nor the folks I immediately had to help me were super well versed with how to go about this but with an incredibly helpful post I was well on my way to using Python and XML.

The final product ended up looking like something like this:

JavaScript

Ultimately I ended up scheduling this script to initiate a call (via cron) and then wrote a very similar script to hang up the call using DisconnectAll.

I hope this helps someone and thanks to /u/omgdave on Reddit (who I’d offered an opportunity to respond to this with an answer but wasn’t taken up on it) for the help with this.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement