Linux – expect script to support two expected characters

bashexpectlinuxshellsolaris

I want to run sshd restart on Linux and Solaris machine via expect ( my expect run in my ksh script )

I create expect script so when expect see the prompt "#" then he run sshd restart

but the problem is that I run this expect also on solars and the prompt there is ">"
so how to create one expect line that support "#" and ">" prompt

on linux

    expect #                {send "/etc/init.d/sshd restart\r"}

solaris

   expect >                {send "/etc/init.d/sshd restart\r"}

Best Answer

Use a glob-pattern: expect {[#>]}

or a regexp: expect -re {#|>} -- the regexp pattern can get more elaborate. I recommend you anchor prompt matching to the end of the line. Often prompts end with a space, so you could:

expect -re {[#>] ?$}