Operating System - HP-UX
1843989 Members
1594 Online
110226 Solutions
New Discussion

embed expect in shell script?

 
Jun Zhang_4
Regular Advisor

embed expect in shell script?

What will the following expect script be like, without the #!/usr/local/bin/expect -f? Or is there such a way at all?
I'm thinking about embed this expect piece in shell script and use as much known script (ksh, for example) syntax as possible.

Jun


set timeout -1
spawn /opt/samba/bin/smbpasswd -a ultvm
match_max 100000
expect -exact "New SMB password:"
send -- "!ultvm!\r"
expect -exact "\r
Retype new SMB password:"
send -- "!ultvm!\r"
expect eof
Food lover
3 REPLIES 3
Sridhar Bhaskarla
Honored Contributor

Re: embed expect in shell script?

Hi,

If you don't want to put #!/usr/local/bin/expect, then you would need to do something like this

#!/usr/bin/ksh #or whatever your shell is


your_shell_script_commands

/usr/local/bin/expect << EOF
set timeout -1
spawn /opt/samba/bin/smbpasswd -a ultvm
match_max 100000
expect -exact "New SMB password:"
send -- "!ultvm!\r"
expect -exact "\r
Retype new SMB password:"
send -- "!ultvm!\r"
expect eof
EOF

rest_of_the_shell_script

Alternatively, you can dump this in a file and ask run expect over that file like

/usr/local/bin/expect your_expect_commands_file

-Sri


You may be disappointed if you fail, but you are doomed if you don't try
Geoff Wild
Honored Contributor

Re: embed expect in shell script?

It won't work - atleast I don't think so...

What we do, is sh script most, then inside the sh script, call the expect script (which we use for sftp).

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Jun Zhang_4
Regular Advisor

Re: embed expect in shell script?

Thanks a lot for the answers. The pull down arrow is not available right now for assigning points. Let me wait and see if it comes back.


Jun
Food lover