Do expect script have "or" statement?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Do expect script have "or" statement?
# 1  
Old 10-26-2011
Question Do expect script have "or" statement?

Do expect script have "or" statement?

sound like this:
Code:
expect {
    "A" or "B" {
        send "123"
    }
    "C" {
        send "567"
    }

I know expect can separate that to do this
Code:
expect {
    "A" { send "123" }
    "B" { send "123" }
    "C" { send "567" }
}

when the expect script getting longer
I need to copy the same part so many times to do that
It is too hard to maintainSmilie

anyone got an idea about that?Smilie
# 2  
Old 10-26-2011
Code:
expect {
    "\[AB]" {
        send "123"
    }
    "C" {
        send "567"
    }

If you real patterns are more complex, you'll need a different solution.
This User Gave Thanks to radoulov For This Post:
# 3  
Old 10-26-2011
I know it does not have everything to do with your question, but have you seen the autoexpect command? Check this link: autoexpect(1) - Linux man page

It may help you...
These 2 Users Gave Thanks to felipe.vinturin For This Post:
# 4  
Old 10-26-2011
Quote:
Originally Posted by radoulov
Code:
expect {
    "\[AB]" {
        send "123"
    }
    "C" {
        send "567"
    }

If you real patterns are more complex, you'll need a different solution.
Thanks for you solution.

And I got some question about that...
Is that just support one character of change inside each square brackets?

How can I define "with space" or "no space" case?
In my situation, I need to login to difference server by using that same expect script. Some of the server using "ftp>", and some using "ftp >"
As your suggestion, I'm trying to expect "ftp\[ ]>"
but it seem doesn't work in this case. Am I missing something?Smilie
# 5  
Old 10-27-2011
This should be sufficient:

Code:
"ftp*>"

This User Gave Thanks to radoulov For This Post:
# 6  
Old 10-27-2011
Quote:
Originally Posted by radoulov
This should be sufficient:

Code:
"ftp*>"

any other solution?
I prefer expect "ftp>" and "ftp >" exactly.
because the output maybe include "ftp" word
and I don't want to separate it Smilie
# 7  
Old 10-27-2011
Yes:

Code:
expect {
    -re "ftp ?>" {
        send "123"
    }
    ...
  }

This User Gave Thanks to radoulov For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

Hi All, i am trying to ssh to a remote machine and execute certain command to remote machine through script. i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as expect: spawn id exp5 not open while executing "expect "$" {... (3 Replies)
Discussion started by: Siddharth shivh
3 Replies

3. Shell Programming and Scripting

Can someone please show me a very simple "expect" script to change password in Solaris please?

Ladies & Gents, Can one of you gurus please show me a very simple "expect" script to change the password in Solaris in a script, please? Nothing fancy, no error checking, no nothing. Just to change the password of a new user, it's all. Many thanks in advance. U guys have honestly earned my... (1 Reply)
Discussion started by: Hiroshi
1 Replies

4. Shell Programming and Scripting

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (14 Replies)
Discussion started by: thisissouvik
14 Replies

5. AIX

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (2 Replies)
Discussion started by: thisissouvik
2 Replies

6. Shell Programming and Scripting

Shell script using expect to login to couple of remote servers and read "crontab -l"

I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP... (4 Replies)
Discussion started by: jaipsharma
4 Replies

7. Shell Programming and Scripting

Expect Script - Variables are Empty immediately after "Setting" Them?

Hello All, I have embedded some expect code inside a Bash script I'm writing, but for some reason any variable I 'set' to something is showing as empty immediately on the next line... I haven't run into this problem before so I'm not sure what it could be...? I'm guessing it has something to... (4 Replies)
Discussion started by: mrm5102
4 Replies

8. Shell Programming and Scripting

Passing username and password to a script running inside "expect" script

Hi I'm trying to run a script " abc.sh" which triggers "use.sh" . abc.sh is nothing but a "expect" script which provides username and password automatically to the use.sh script. Please find below the scripts: #abc.sh #!/usr/bin/expect -f exec /root/use.sh expect "*name*" send... (1 Reply)
Discussion started by: baddykam
1 Replies

9. Shell Programming and Scripting

exec perl in expect script yields "invalid command"

I'm trying to execute something like this: exec perl -i -pe 's/\015/\012/g' '${file}' in my expect script and I get: error "invalid command name \"perl\". however, if I run perl -i -pe 's/\015/\012/g' "/Users/Shared/menu-items.txt" directly in my terminal, it runs fine. I'm an... (4 Replies)
Discussion started by: dpouliot
4 Replies

10. Shell Programming and Scripting

question about "sleep" command in expect script

I wrote some expect script to telnet to some device to execute some commands.Firstly,I can't get full result some time,then I try to add some "sleep" command in it.Fortunately it works. My idea about it is that it uses sleep command to wait the result to be displayed.Am I right or correct the... (4 Replies)
Discussion started by: robbiezr
4 Replies
Login or Register to Ask a Question