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:

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 with username 'sshuser'
spawn ssh [email protected]
# 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 [email protected]
[email protected]'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
LXI> sc 1
LXI> bv
LXI> sc 5
LXI> bv
LXI> All done

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´╝č


Search our knowledgebase for information on software drivers, product comparisons and technical support for our entire product range.


Product Selector

Because we offer such a large range of products, this tool will help you narrow down our offering to get you the correct switch and simulation solution you need.

Try the selector

Resource center

From success stories and product videos to product literature and 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