Sponsored Content
Top Forums Shell Programming and Scripting Expect Script square bracket dollar prompt Post 302400732 by Ikaro0 on Thursday 4th of March 2010 03:32:40 AM
Old 03-04-2010
Hi,
Thanks a log for the quick replay but I think it is not good cause it sems that no matter what if founds it continues.

I'll explain better the situation:

Environment: Production, servers don't allow for root ssh connections.

The need that I had was to create a script for creating users on all the servers (more than 200 Unix,Linux)

What I've done so far is:

I had created a script that login each server with gets "user login name", "user password" and "user to be created"

The the script reads from a file, the servername and rootpassword and apss all the information to the expect script in form of parameters

The expect script uses the parameters ($0 $1.....) for connecting to the servers as the entered user, puts the password, changes to root, sends useradd....."user to be created" and then logs of and continue to the next one.

The thing here is that the script works but due to differences on the servers I need to cover all the posibilities for it to work fast and without error.

for login I had the following at the script:

spawn ssh $username@$ipaddr
match_max 100000
Code:
expect_after {
    eof {send_log "\nEXP-ERROR---No se ha podido conectar con $ipaddr\n" ; exit 1 }
}
expect {
        timeout {send_log "\nEXP-ERROR---TIMEOUT No se ha podido conectar con $ipaddr\n" ; exit 1 }
        "(yes/no)?"   {send "yes\n"}
        "*?assword:" {send "$userpass\r"}
        }

and then :

Code:
expect  {
        ".*\?"      {send "\n";sleep 1;send "\n"} ----for servers that ask for oraclehome
        ".*\$"          {send_log "\nEXP-EXEC---Login correcto\n"}
        "*?assword:"    {send_log "\nEXP-ERROR---Password de usuario $username incorrecto o usuario inexistente en $ipaddr" ; exit 1 }
        }

because I set timeout to -1 the script waits for ever when it logs into a server with the prompt "[whatever]$"

but putting the timeout to 5(for example) I pass (waiting) the $ paths and after entered "su -" and password, it recognise well the "[whatever]#" prompt for root and don't wait at all, sending the useradd command in no time.

Thanks a lot
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract string in square bracket

Hi Input text is some message some message some message Expected output is main value1 value2 value3 Any idea how to above values in square brackets using shell scripting? many thanks. (3 Replies)
Discussion started by: hnh
3 Replies

2. Shell Programming and Scripting

Expect, save to file and remove before prompt

I have an Expect script which works very well. It logs into my remote routers and runs some commands and then to the next until finished. I need two things, first I need to save the output to a file from where the log_user 1 begins. expect << EOF set timeout 15 #set var "exit " match_max... (1 Reply)
Discussion started by: numele
1 Replies

3. Shell Programming and Scripting

Group on the basis of common text in the square bracket and sorting

File A 99 >ac >ss >juk 70 >acb >defa 90 >ca 100 >aa >abc >bca 85 >cde 81 >ghi >ghij 87 >def >fgh <ijk 89 >fck >ghij >kill >aa The given output shud be 100 >aa >abc >bca 87 >def >fgh <ijk 89 >fck >ghij >kill >aa (2 Replies)
Discussion started by: cdfd123
2 Replies

4. Shell Programming and Scripting

Handling SQL prompt through Perl expect module

Hi All, I have a doubt whether expect module in perl will work in SQL prompt or its applicable only for shell prompt ? Thanks, Arun V (2 Replies)
Discussion started by: arun_maffy
2 Replies

5. Shell Programming and Scripting

ksh, difference between double bracket and single bracket

Can somebody tell me the difference between double brackets and single brackets, when doing a test. I have always been acustomed to using single brackets and have not encountered any issues to date. Why would somebody use double brackets. Ie if ] vs if Thanks to... (2 Replies)
Discussion started by: BeefStu
2 Replies

6. Shell Programming and Scripting

Expect doesn't recognize a password prompt

Hi. Here is beginning of my script #!/usr/local/bin/expect -- set timeout 15 spawn /usr/local/account.sh -n modify expect "Password:" {send "mypassword\r"} But due to some terminal control sequences (or something else, dunno exactly) my password prompt is looking like this: and expect... (3 Replies)
Discussion started by: urello
3 Replies

7. Shell Programming and Scripting

Doubt with regex to replace square bracket

there is a word "welcome" output should be "welcome\ i am using regsub to add backslash "\" in place where ever i find square brackets (open or close).. But i am not getting it... pls help out.. set a {welcome} set d (5 Replies)
Discussion started by: Syed Imran
5 Replies

8. Shell Programming and Scripting

Expect prompt extending to next line

Hi guys, I am trying to install a software which is a shell script. I am using expect to do the silent installation. There is a strange line during the installation of the software like this below. The prompt goes to the next line. ENTER AN ABSOLUTE PATH, OR PRESS <ENTER> TO ACCEPT THE... (0 Replies)
Discussion started by: kapkap
0 Replies

9. Shell Programming and Scripting

Expect script not expecting the password prompt

I have a script that does an SSH into a remote node. It should expect the prompt and send the password. #!/usr/bin/expect set user ; set pass ; spawn ssh $user@E-Internal expect { -re "RSA key fingerprint" {send "yes\r"} timeout... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

10. Shell Programming and Scripting

Dollar symbol in Shell Script Variable

Hi, I am working on PGP encryption. I am getting public keys from some file. One of the key has dollar sign in it "$" Example: "abc$123" echo 'passphrase='$passphrase --> Giving correct value abc$123 But if I use $passphrase in PGP command getting Invalid passphrase error. If I... (10 Replies)
Discussion started by: Sreehari
10 Replies
PPIx::Regexp::Constant(3pm)				User Contributed Perl Documentation			       PPIx::Regexp::Constant(3pm)

NAME
PPIx::Regexp::Constant - Constants for the PPIx::Regexp system SYNOPSIS
use PPIx::Regexp::Constant qw{ TOKEN_UNKNOWN } print "An unknown token's class is TOKEN_UNKNOWN "; INHERITANCE
"PPIx::Regexp::Constant" is an Exporter. "PPIx::Regexp::Constant" has no descendants. DETAILS
This module defines manifest constants for use by the various "PPIx::Regexp" modules. These constants are to be considered private to the "PPIx::Regexp" system, and the author reserves the right to change them without notice. This module exports the following manifest constants: COOKIE_CLASS The name of the cookie used to control the construction of character classes. This cookie is set in PPIx::Regexp::Token::Structure when the left square bracket is encountered, and cleared in the same module when a right square bracket is encountered. COOKIE_QUANT The name of the cookie used to control the construction of curly bracketed quantifiers. This cookie is set in PPIx::Regexp::Token::Structure when a left curly bracket is encountered. It requests itself to be cleared on encountering anything other than a literal comma, a literal digit, or an interpolation, or if more than one comma is encountered. If it survives until PPIx::Regexp::Token::Structure processes the right curly bracket, it is cleared there. COOKIE_QUOTE The name of the cookie used to control the parsing of "Q ... E" quoted literals. This cookie is set in PPIx::Regexp::Token::Control when a "Q" is encountered, and it persists until the next "E". MINIMUM_PERL The minimum version of Perl understood by this parser, as a float. It is currently set to 5.000, since that is the minimum version of Perl accessible to the author. MODIFIER_GROUP_MATCH_SEMANTICS The name of the PPIx::Regexp::Token::Modifier group used to control match semantics. RE_CAPTURE_NAME A string representation of a regular expression that matches the name of a named capture buffer. STRUCTURE_UNKNOWN The name of the class that represents the unknown structure. That is, PPIx::Regexp::Structure::Unknown. TOKEN_LITERAL The name of the class that represents a literal token. That is, PPIx::Regexp::Token::Literal. TOKEN_UNKNOWN The name of the class that represents the unknown token. That is, PPIx::Regexp::Token::Unknown. SUPPORT
Support is by the author. Please file bug reports at <http://rt.cpan.org>, or in electronic mail to the author. AUTHOR
Thomas R. Wyant, III wyant at cpan dot org COPYRIGHT AND LICENSE
Copyright (C) 2009-2012 by Thomas R. Wyant, III This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. perl v5.14.2 2012-06-06 PPIx::Regexp::Constant(3pm)
All times are GMT -4. The time now is 03:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy