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?

2 Answers 2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .