2

I am using KALI Linux and have some trouble with an expect script.

I don't know why the spawn command doesn't perform any action, it just echos out the same text

#!/usr/bin/expect -f
spawn apt-get install expect

OR

#!/usr/bin/expect -f
spawn ssh 10.10.80.1

it just prints out the same text when I execute it using ./test.sh , here is the result

spawn apt-get install expect

AND

spawn ssh 10.10.80.1

What am I doing wrong?

3

The problem is that expect runs your spawn command, which starts apt-get, then expect gets to the end of the script and so it stops, and the apt-get is killed by a signal SIGHUP.

At the very least you should add another line

expect eof

to your script to make expect read from the spawned command until it gets end-of-file.

2
  • send – to send the strings to the process
  • expect – wait for the specific string from the process
  • spawn – to start the command

You must close every command that spawn initiates, else it will read it as a line.

Your expect script should look like this using EOF:

#!/usr/bin/expect -f
spawn ssh 10.10.80.1
expect EOF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.