Sponsored Content
Top Forums Shell Programming and Scripting comprehensive expect examples Post 302356276 by Gavster on Friday 25th of September 2009 04:33:50 AM
Old 09-25-2009
Hi,

I wrote an expect script to log in to all cisco switches on our network which uses telnet. The main problem for me was that the usernames and passwords weren't consistent across all switches. My code looked like this ...
Code:
log_file -noappend ./CDP_LOGS/$ip_addr.log
# This spawns the telnet program and connects it to the IP address
 spawn telnet $ip_addr
 #The script expects Password or Username or times out if no response is seen
 expect {
   "Password: "  {login1a $ip_addr}
   "Username: "  {login2a $ip_addr}
   timeout       {abort $ip_addr 1}
 }
 log_file

If "Password: " or "Username: " are identified, the appropriate proc is called (either login1a or login2a respectively). Once logged in successfully, you can continue to send commands using this construct:
Code:
send "command"
 while {1} {
   expect "some output 1" {
     do stuff
   } "some output 2" {
     do stuff
     break
   } "some output 3" {
     do stuff
     break
   }
 }

This expects multiple things and reacts accordingly.

All my output was logged to a file which I used for post-processing.

Hope this is helpful.

Gavin

Last edited by Gavster; 09-25-2009 at 11:06 AM..
 

2 More Discussions You Might Find Interesting

1. Solaris

Comprehensive system documentation by button click

Guys There's a new WebPage where you can generate a comprehensive detailed system documentation by button click. Look at the example at https://sdoctool.sun.com/data/doc.php?ID=sdoctool&N=2 ;) Interested, go to Cheers (0 Replies)
Discussion started by: lebch
0 Replies

2. Red Hat

Comprehensive Disk & Server Logs.

Hello All, I'm using a RHEL6.4 on IBM X3850 X5 server. I want to get a comprehensive report containing disk-wise health status as well as overall server status. I see there's utility "ibm_utl_dsa_dsytd3h-9.51_portable_rhel6_x86-64.bin" which is also used to do diagnostics tasks. I'm not sure of... (1 Reply)
Discussion started by: vaibhavvsk
1 Replies
runtest(1)						      General Commands Manual							runtest(1)

NAME
runtest - the DejaGnu test driver program SYNOPSIS
runtest [ options ] DESCRIPTION
DejaGnu is a framework for running test suites on GNU tools. It is written in expect, which uses TCL (Tool command language). runtest is the test driver program; use it to control what tests to run, and variations on how to run them. You can find a comprehensive description of DejaGnu and runtest in The DejaGnu Testing Framework or its Info version, dejagnu.info. OPTIONS
--all Print all test output to screen. By default, only unexpected results are displayed. --baud rate Set the baud rate for a serial line connection. Some serial interface programs (like tip) don't use this value but instead use a separate initialization file. --connect type The type of connection to use. The choices are rlogin, telnet, rsh, kermit, tip and mondfe. --debug Turn on expect internal debugging output. All output is logged to a file called dbg.out. The output of the --strace also goes into this file. --help Prints out a help screen and then exits. --host type The configuration string for the host. --ignore test1.exp test2.exp ... Do not run the specified tests. Electronic mail addresses to receive test results. --name hostname The network hostname of the target board. --objdir path path is a directory containing compiled test code. --outdir directory The name of a directory for test log output. --reboot Reboot the target board when runtest initializes (if supported). --srcdir path path is a directory containing test directories. --strace N Turns on expect internal tracing to N levels deep. --target type The configuration string for the target. --tool toolname Specify the tool to be tested. toolname controls the test suite applied, and the associated initialization module. --verbose, -v Turns on more debugging output from test cases and DejaGnu utility code. Use more than once to increase output further. --version, -V Prints out the versions of DejaGnu, expect and Tcl. -D[number] Activate the Tcl debugger.number can be either 1 or 0. If it is 1, then the expect shell will break when it starts to run. All ^C's drop DejaGnu back to the debugger prompt. A 0 starts DejaGnu like normal, but a ^C drops to the debugger prompt. Any file name on the command line is assumed to be a subset of the test names to run. Usually these are the names of the expect test driver, ie... special.exp. Makefile style variables are used to specify tool names and their flags; these and other configuration dependent values are saved in the file site.exp, created during configuration. EXIT CODES
runtest sets the exit code to 1 if any of the tests failed, or sets it to 0 if all the tests passed. SEE ALSO
The DejaGnu Testing Framework (dejagnu.info). This is the DejaGnu manual; its source is the SGML files doc/*.sgml. in the DejaGnu distri- bution. AUTHOR
Rob Savoye (rob@welcomehome.org) 08 Dec 1998 runtest(1)
All times are GMT -4. The time now is 06:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy