#!/usr/bin/expect not working
10,416
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 [email protected]
1.1.1.1
testuser
Related videos on Youtube
Author by
Jim
Updated on September 18, 2022Comments
-
Jim almost 2 years
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
-
John about 9 yearsWhat error (if any) are you getting?
-
Jim about 9 yearsspawn command not found
-
krisFR about 9 yearsPlease can you post post the full error ?
-
Paul Haldane about 9 yearsHow are you running the script? Does it work as expected if you explicitly run it using expect (
expect -f textexpect.exp
)? Is the #! line the very first line of the file (that includes blank lines - the first two characters of file should be #!). -
Paul Haldane about 9 yearsAlso (not related to your immediate issue)
echo
isn't anexpect
command. You probably wantsend_user
. -
John about 9 years@Paul - actually,
echo
is valid inexpect
. It simply echoes the value passed to it to STDOUT. -
Paul Haldane about 9 years@John - that's a
tcl
feature rather thanexpect
and only applies to interactive shells not within scripts (at least by default). See wiki.tcl.tk/2541
-