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



Knowledgebase

Information on software drivers, product comparisons and technical support for our entire product range.

Knowledgebase


Product Selector

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

Success storiesproduct videos and more—find the information you need about our switching and simulation.

Resources you need


Worldwide presence

Find support across the globe, with offices and agents in the Americas, Europe and Asia. 

Find local office or agent