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
fence_mcdata(8) 					      System Manager's Manual						   fence_mcdata(8)

NAME
fence_mcdata - I/O Fencing agent for McData FC switches SYNOPSIS
fence_mcdata [OPTION]... DESCRIPTION
fence_mcdata is an I/O Fencing agent which can be used with McData FC switches. It logs into a McData switch via telnet and disables a specified port. Disabling the port which a machine is connected to effectively fences that machine. Lengthy telnet connections to the switch should be avoided while a GFS cluster is running because the connection will block any necessary fencing actions. fence_mcdata accepts options on the command line as well as from stdin. fenced sends parameters through stdin when it execs the agent. fence_mcdata can be run by itself with command line options which is useful for testing. After a fence operation has taken place the fenced machine can no longer connect to the McData FC switch. When the fenced machine is ready to be brought back into the GFS cluster (after reboot) the port on the McData FC switch needs to be enabled. This can be done by running fence_mcdata and specifying the enable action. Vendor URL: http://www.brocade.com OPTIONS
-a IPaddress IP address of the switch. -h Print out a help message describing available options, then exit. -l login Username name for the switch. -n port The port number to disable on the switch. -o action The action required. disable (default) or enable. -p password Password for login. -S path Full path to an executable to generate the password for login. -q Quiet mode: print only error messages. -V Print out a version message, then exit. STDIN PARAMETERS
agent = < param > This option is used by fence_node(8) and is ignored by fence_mcdata. ipaddr = < hostname | ip > IP address or hostname of the switch. login = < param > Login name. option = < param > The action required. disable (default) or enable. passwd = < param > Password for login. passwd_script = < param > Full path to an executable to generate the password for login. port = < param > The port number to disable on the switch. SEE ALSO
fence(8), fence_node(8) fence_mcdata(8)
All times are GMT -4. The time now is 11:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy