1

i have a expect script like

#!/usr/bin/expect
.....
spawn passwd
expect "password:"
send "password"
....
....
....
~/test.sh

Wile executing this, I'm unable to run bash script test.sh.

How to execute Linux commands/bash scripts inside Expect script?

2 Answers 2

7

You can use the tcl exec command, which normally collects the output, so redirect it:

#!/usr/bin/expect
...
exec ~/test.sh  >@stdout
1
1

To begin with you should use spawn to run your script, and I'm not certain the tilde construct will be interpreted by expect.

spawn /bin/bash /home/username/test.sh

You should have error messages when this happens, you should add the to your question if you do not understand them.

You must log in to answer this question.