expect-script-with-comments
!/usr/bin/expect
john pfeiffer 2009-11-24 script(s) to add user to an htpasswd file
the script will wait 1 second for any command to finish
set timeout 1 set username [lindex $argv 0] set userpass [lindex $argv 1]
the two parameters are the new username and password
we are creating a thread specifically to run the next script as the user "scriptuser"
spawn su scriptuser -c "/path/wiki-add-user.sh $username $userpass"
it is KEY to get the exact text of the "expect" line right, in this case, notice the trailing space
expect "Password: " send "password\n"
the expect script "catches" the prompt by SU for the password - you need the newline \n
the script must sleep for 1 second at the end to allow the "spawned" thread to finish
every "spawn" command requires an interact command to give control back to the prompt
sleep 1 interact