Trying to script an application's interactive add-user function with expect/send.
So far no information is sent, but the add-user function is called.
Any help appreciated! Many Thanks
#!/bin/sh
#!/usr/bin/expect -f
#PATH to add-user: PATH to expect
PATH=/opt/app-1/sbin:/usr/bin
#Set Variables
set login "app-adm2"
set password "App-password"
#Add user command
app1-adduser
expect "*?ogin :*"
send -- "$login\r"
expect "*?ogin password :*"
send -- "$password\r"
expect "*?ogin password (again) :*"
send -- "$password\r"
expect eof
I think you might want to use:
spawn app1-adduser
Also, have a look at autoexpect to generate some code based on a real interactive session.
Thanks Peterro!
Autoexpect worked like a charm!
$autoexpect -p ./app1-adduser
(note: I used -p flag b/c some text from app1-useradd broke the script when it read directly from interactive session. -p flag looks for the prompt. man autoexpect has info.)
Here is the code it generated:
set timeout -1
spawn ./app1-adduser
match_max 100000
expect -exact "Login : "
send -- "app-adm\r"
expect -exact "Login password : "
send -- "App-password\r"
expect -exact "Login password (again) : "
send -- "App-password\r"
expect eof