Acquisition of data - Telnet?

To obtain some information, my historical method has been to Telnet to the machine needed and via commands, see what I need onscreen and write the numbers down.

How can I automate this and have Panorama acquire the data? What tools would I use with Panorama?

It depends on what the commands are. If you can set the whole thing up with a shell script, with no interactive components, you can do it with the shellscript command. But if any interaction is required, it can’t be done as far as I know.

While in Terminal I type…

telnet
open [IP_Address] 10001 (10001 is the port number)
^a200 (^ = Control)

I then see the text that I need to scrape.

Robert Ameeti

Yeah, your telnet session is interactive. I don’t know of any way to automate that. Maybe it can be done, but I don’t know how. If you figure it out, I’d like to know.

Theoretically it seems it might be possible using the expect method in a shellscript. There are examples that show what would normally be an interactive telnet session being handled completely via an expect script.You can find more info on expect at http://expect.sourceforge.net/.

Yep. Expect is the answer. I am working on a ShellScript at this moment with some Expect as part of it.

Expect is supposed to make it trivially easy but at the moment, I’m not moving forward very fast as I’ve not done much with BatchScripts. I keep putting it aside, picking it up again, and then putting it aside. I figure that the whole scripting this will make sense within a day or 2.

Robert Ameeti

The answer to working with a Telnet session in an interactive mode is to write an Expect script. The following is my script with some default values being set for variables for the IP address and location name that I will be supplying with my script when I call it. I’ve also set a default report number and am setting my default out to a text file in date.time.location.txt format.

#!/usr/bin/expect
#!/usr/bin/tclsh

set CTRLA \001        ;# Continue the script
set port 10001

set ip [lindex $argv 0]			;# required parameter
set location [lindex $argv 1]		;# required parameter (defaults = to 'unknown')
set report [lindex $argv 2]		;# optional parameter; options = are 100 or 200, defaults to 200

if {$ip == ""} {
	set ip "104.49.172.227"
	set location "Artesia"
}
if {$location == ""} {
	set location "unknown"
}
if {$report == ""} {
	set report "200"
}

set fname  [clock format [clock seconds] -format = %y%m%d.%H%M].$location.txt

 log_file -noappend $fname

spawn telnet $ip $port

sleep .1;

expect "'^]'."

send $CTRLA
send $report"\r\n"

if {$report >=200} {
	set report [expr $report - 100]
	send $CTRLA
	send $report"\r\n"
}
expect "'^]'."

The forum seems to have deleted your script from the email. I retrieved it from the raw email and formatted it as code. Hopefully, I haven’t made any editorial mistakes in the process.