john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Expect script continued

linux-script-expect-continued

to execute the file with the "expect interpreter" you must begin the script with one of the three (depending where your expect binary has been installed)

!/usr/bin/expect

!./expect -f

!../expect -f

DON'T FORGET to chmod +x scriptname.sh


VARIABLES

test.sh

!/usr/bin/expect

set password [lindex $argv 0] send $password\n

./test.sh testvar

testvar


USING EXPECT WITH OTHER BINARIES (with the "spawn" command) THE INTERACT command returns control to the command line prompt user

!/usr/bin/expect

set username [lindex $argv 0] set userpass [lindex $argv 1]

spawn htpasswd example $username

interact


HERE IS A REAL WORKING EXAMPLE OF expect helping htpasswd modify the "example" password file - NOTE that "interact" must be at the end of the script!

!/usr/bin/expect

set username [lindex $argv 0] set userpass [lindex $argv 1]

spawn htpasswd example $username

expect "New password:" send $userpass\n

expect "Re-type new password:" send $userpass\n

interact



  • « Linux script continued
  • Expect non interactive ssh »

Published

Feb 6, 2010

Category

linux

~140 words

Tags

  • continued 26
  • expect 7
  • script 19
  • scripts 63