Expect Script square bracket dollar prompt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect Script square bracket dollar prompt
# 1  
Old 03-03-2010
Network Expect Script square bracket dollar prompt

Hi

Thanks for this amazing forum first, I've been searching answers in it for problems that I've encountered at work.

The only problem I haven't been able to find a fix for, is a ever waiting for prompt problem in Expect when encounter a [whatever]$ prompt.

I usually set the timeout to -1 cause the script runs faster if every string I wrote at it match's but I have problems with the prompt referred above.

Id tried to "set mpt "\$" and then expect -- "$mpt" or
"set mpt "\]\$" or simple "expect -- *\]\$?]" and non of them worked.

Does anyone had similar problems?

Thanks in advance for any help.
# 2  
Old 03-03-2010
I use regular expressions in Expect and by using the wild card am able to match everything in the buffer up to the '$' prompt.
Code:
expect -re ".*\$" {
  send_user "HI\n";
  send "\r";
}

# 3  
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question