Using Expect with SSH on an LXI Device

Secure Shell (SSH) is typically used to allow users to remotely login to an account using an interactive command line terminal, Pickering LXI devices offer an SSH service. This is normally of little use as programming interface, however software products exist which allow the user to convert such an interactive interface into a programming interface, one such product is Expect. Expect allows the user to create a program, written in Tcl, the native language of Expect, to handle interactive command line interfaces.

More information on the Pickering SSH interface can be found here.

More information on the PILMon command line utility can be found here.

Expect may be obtained from: http://expect.nist.gov/

Here is a simple Expect script which gains access to a Pickering LXI device, clears the first subunit, then sets some switches and obtains the current switch settings. The LXI device was set up with SSH enabled, and a password of 'lxi'.

#!/usr/bin/expect -f
 
# Start SSH session on device at 192.168.50.130 with username 'sshuser'
spawn ssh sshuser@192.168.50.130
 
# wait until the text 'password:' is returned from the session, then reply with the password 'lxi'
expect "password:"
send "lxi\r"
 
# wait until the prompt 'LXI>' is returned
expect "LXI>"
 
# clear the default subunit on the LXI device
send "cs\r"
expect "LXI>"
 
# set bit 1
send "sc 1\r"
expect "LXI>"
 
# obtain settings of all switches on current subunit
send "bv\r"
expect "LXI>"
 
# now set bit 5
send "sc 5\r"
expect "LXI>"
send "bv\r"
expect "LXI>"
 
# quit remote SSH session
send "q\r"
puts "All done"
 

The output of the above script is shown here:

debian:~# ./testssh
spawn ssh sshuser@192.168.50.130
sshuser@192.168.50.130's password:
 
Monitor Program for Pickering Interfaces PXI Cards
==================================================
Version 1.55
(c) Pickering Interfaces Ltd. 20 Sep 2007
 
PILPXI Driver version number = 286
Number of Pickering cards opened = 1
Selected card 1, sub-unit 1: Input = none, Output = SWITCH(10)
Enter 'HE' for help.
 
LXI> OK, we're in
cs
OK
LXI> sc 1
OK
LXI> bv
001
LXI> sc 5
OK
LXI> bv
011
LXI> All done
debian:~#
 

NOTE: The example above uses a Pickering switch card with a 10 bit wide subunit representing a group of 10 switches, the returned results are in hexadecimal format with the least significant bit representing bit 1 of the switch group.

Need help?



Support knowledgebase

Have questions or need some help? While we enjoy talking to you, you can find technical information for our entire product range here.

Technical know-how 


Long-term support

Because we manufacture our products in-house, we are able to provide you with guaranteed long-term support and low obsolescence.

Our support


Resource center

From success stories and product literature to newsletters, find the information you need about our switching and simulation solutions.

Get the resources you need


Worldwide presence

We supply and support our products across the globe, with seven offices in the Americas, Europe and Asia as well as additional representation. 

Find a local office or agent near you