#!/usr/bin/expect not working

expectscriptingshell-scripting

This is probably an easy question, however have a simple expect script that I've add the executable bit to that seems to be ignoring the #!/usr/bin/expect interpreter line. Further more, it also seems like variables are not being set since when I echo them they are blank…

#!/usr/bin/expect -f
set device "1.1.1.1"
set user   "testuser"

spawn ssh $user@$device
echo $device
echo $user

ls -lh
-rwxr-xr-x  root  root    testexpect.exp

Thanks for your help community!!

P.S. I'm running Debian Wheezy, installed expect via apt-get install expect…thanks

Best Answer

Expect is based on Tcl language, so you shouldn't use bash 'echo' - you should use 'puts' to print something on the screen:

#!/usr/bin/expect -f
set device "1.1.1.1"
set user   "testuser"
spawn ssh $user@$device
puts $device
puts $user

And you will got result like this:

$ ./test.exp
spawn ssh testuser@1.1.1.1
1.1.1.1
testuser