john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

expect script with comments

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


  • « eventquery
  • exchange server multiple domain to test google postini »

Published

Feb 6, 2010

Category

research

~142 words

Tags

  • comments 7
  • expect 7
  • research 199
  • script 19
  • with 29