Sponsored Content
Top Forums Shell Programming and Scripting Tcl / expect need to attempt telnet if failed ssh Post 303028288 by Don Cragun on Thursday 3rd of January 2019 02:51:53 PM
Old 01-03-2019
Maybe I'm not understanding your question.

The script you showed us in post #1 in this thread invokes expect four times. The first invocation has three conditions and corresponding actions to be performed if any one of those three conditions are met. That is a classical logical OR operation. The first two conditions in that expect are literal string matches and the last is a timeout condition. You also have a commented out regular expression match that would match either of two other literal strings separated by a vertical bar symbol (|) that also acts as a logical OR when matching either of the literal strings Conection refused and Connection timed out and gives an action that is to be performed if either of those literal strings are matched.

Note that the first two patterns and actions in the first invocation of expect have identical actions (i.e. { send "$unam\n"; }) so the two patterns and actions:
Code:
             "sername" { send "$unam\n"; }
             "login"   { send "$unam\n"; }

should be able to be replaced by:
Code:
             -re "sername|login" { send "$unam\n"; }

and get the same results.

The action in the commented out regular expression match seemed to be incomplete because it didn't include the additional steps in the action that were present in the timeout condition's action after spawning ssh. Each action for a pattern has to be complete; actions for one pattern are never used when another pattern is matched.

Unfortunately, there is no regular expression that can look for various strings AND look for the timeout condition. So, you have to duplicate the actions that you have for the timeout condition as the actions to be performed for the regular expression match of the two strings.

Since there is no opening brace ({) between the expect and the pattern for the last threee invocations of expect in your script, there can only be one pattern and action for each of those invocations of expect. The first invocation of expect in your script has braces surrounding the three patterns (and the comment that will be ignored) that will be acted upon whenever the first, second, OR third pattern is matched in the input that expect is reading.

Does this cover what you're trying to do?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect with tcl/tk

hai all, i have an tcl script in which i have been reading the DUT Command prompt of an cisco switch as DUT Command Prompt : cisco* and running the test case of stp now the problem is if i have given any blank space in between the cisco or at the startup then the Expect is not identifying the... (0 Replies)
Discussion started by: sanjustudy
0 Replies

2. UNIX for Dummies Questions & Answers

Expect/Tcl help?

Does anyone know of an expect/tcl forum that is as helpful as this one is for shell scripting? Or if anyone has any expect knowledge, can you please provide some guidance on how to write to a local error log based on output from a ssh session? I have something like this: foreach host... (2 Replies)
Discussion started by: earnstaf
2 Replies

3. Shell Programming and Scripting

Tcl expect HELP

In the following "for" loop I assume the the script will expect "anyway", "first" NOT in any paticular order and send "yes" when there found, breaking out of the loop when "$prompt" is found. The way it is working is like 3 individual expect lines, and they MUST be in cronological order. ANY help... (0 Replies)
Discussion started by: dave_m
0 Replies

4. Shell Programming and Scripting

tcl/expect

Can someone identify what is the problem here?. no children while executing "exp_wait -nowait -i -1" (procedure "logOptions" line 45) invoked from within "logOptions" (procedure "doExecute" line 98) invoked from within "doExecute" (procedure "main" line 32) ... (7 Replies)
Discussion started by: calsum
7 Replies

5. Shell Programming and Scripting

Webpage to Telnet via Perl and Expect: Telnet problem?

Somewhat long story: I have a simple Perl CGI script that uses Expect to Telnet to a device and grab some data, and then spits it back to Perl for display on the Webpage. This works for many devices I've tried, but one device just fails, it keeps rejecting the password on this device, only... (1 Reply)
Discussion started by: jondo
1 Replies

6. Shell Programming and Scripting

Need 'expect' help, ssh/telnet and trapping

So here is what I am trying to do. I have a large # of switches and routers I am trying to log into. Unfortunately some have ssh only, some have telnet only. and some i have never logged into with ssh. I first want it to SSH, if i have never logged into the box it will ask for adding the ssh key. I... (0 Replies)
Discussion started by: ippy98
0 Replies

7. UNIX for Dummies Questions & Answers

Expect/Tcl help

hi, I am new in Expect. I have a question about expect timeout. suppose I have a structure of expect { ".."{ send"............"} timeout{ ............... } } The silly question is if I reach timeout, how can I store the error message showing on the screen to... (2 Replies)
Discussion started by: allenxiao7
2 Replies

8. Shell Programming and Scripting

tcl/expect magic ssh dictionary password

Hi gurus, I am trying to do some expect/TCL magic. My goal is to write some kind of password guessing script (nearly similar to dictionary attack against ssh). I read that this could be possible with expect/TCL, I am newbie in this language, its function and its terms so please be patient ;) ... (3 Replies)
Discussion started by: wakatana
3 Replies

9. Programming

Failed SSL Connection Attempt

The below error message I started seeing using Ubuntu 14.04 and was wondering if the forum has seen it because I cant seem much on the net for this: perl -e 'use IO::Socket::SSL qw(debug3);IO::Socket::SSL->new(PeerAddr=>"10.0.0.100",PeerPort=> 443,Proto=>"TCP") or die $!' DEBUG:... (1 Reply)
Discussion started by: metallica1973
1 Replies

10. Forum Support Area for Unregistered Users & Account Problems

Further to my query re: failed attempt to change email address on existing account

Neo Thanks for your reply to my original post, entitled "Problem changing the email address associated with my unix.com account". I am unable to reply to you in that thread, as I am unable to log-on to unix.com! From what you said about purging dormant accounts, it is likely that my account... (1 Reply)
Discussion started by: irb
1 Replies
All times are GMT -4. The time now is 09:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy