
16
Sample Tcl/Expect script
#!/usr/bin/expect
##############################################################################
# This script switches the given port and verifies if the port is switched from a remote machine
# Command Usage: rosctl -p <port#> on|off
##############################################################################
# For windows uncomment following
# exec tclsh "$0" ${1+"$@"}
# package require Expect
# Check number of arguments passed to this command if < 3 then spit out error & exit
if { $argc < 3 } {
puts "Usage: rosctl -p <port#> on|off\n"
exit 1
}
# Set telnet host, username, password and other parameters, modify these to reflect your setup
set hostname "192.168.2.20"
set username "osctl"
set password "osctl"
set prompt "osctl@.*\$"
set port [lindex $argv 1]
set status [lindex $argv 2]
set commandcontrol "osctl -p $port $status"
set commandstatus "osctl -s $port"
# Display info.
puts "Connecting to $hostname."
# Connect to the telent server using the "spawn" command.
spawn telnet $hostname
#spawn C:\Putty\putty.exe -telnet $hostname
# Wait for a login prompt.
expect -re "(Name|login|Login|Username).*:.*" {
# Login prompt received. Send user name to fc811/FC811.
send "$username\r"
} eof {
# No login prompt received. Display an error.
Содержание FC811
Страница 10: ...10 delete all groups in the database...
Страница 12: ...12...
Страница 18: ...18 Terminate telnet send exit r...