Operating System - Linux
1825930 Members
2820 Online
109689 Solutions
New Discussion

Expect Scripting Procedures

 
Partha_7
Occasional Contributor

Expect Scripting Procedures

Hi Expect Expert's ,

Thanks in advance!
I have furnished a expect code below , I need the below code to be written using a procedure.
for instance: create/delete role statements are repeating in more than place, so we can coin it under a single procedure, likewise.

since I am naive user of expect, I am facing difficulties using regular expressions to be used along with expect statement too, so only my expect statements look pretty lengthy, plz do help me in that also and in writing procedure.

please do help me in making the below code procedurised and code length reduced!

Thanks a lot ppl,
Partha

set timeout 10
spawn ssh -l abtest 198.16.23.56
match_max 100000
expect -exact "abtest@198.16.23.56's password:"
send -- "ab123\r"
expect -exact "\r
iq2-mgmt:/opt/WINWhdtst> "
send -- "../win/m1gc/bin/m1sh"
expect -exact "../win/m1gc/bin/m1sh"
send -- "\r"
expect -exact "\r\r
Copyright (c) 2005 Win Profsystems, Inc. All rights reserved\r
Use is subject to license terms.\r
\r
N1-ok> "
send -- "create role testt"
expect -exact "create role testt"
send -- "\r"
expect -exact "\r
N1-ok> "
send -- "create role testt"
expect -exact "create role testt"
send -- "\r"
expect -exact "\r
\"testt\" already exists.\r
N1-ok> "
send -- "delete role testt"
expect -exact "delete role testt"
send -- "\r"
expect -exact "\r
N1-ok> "
send -- "create role testt"
expect -exact "create role testt"
send -- "\r"
expect -exact "\r
N1-ok> "
send -- "delete role testt"
expect -exact "delete role testt"
send -- "\r"
expect -exact "\r
N1-ok> "
send -- "exit"
expect -exact "exit"

send -- "\r"
expect -exact "\r"
send -- "exit"
expect -exact "exit"
send -- "\r"
expect -exact "\r"
expect eof