Linux – How to use wget in an Expect script

bashexpectlinuxscripting

I first download a file to /root/TRY1/:

#!/usr/bin/expect
cd /root/TRY1/
exec wget --http-user $user --http-password $password $url

Then I want to extract the file:

cd /root/TRY1/
exec bash -c "tar -xzvf /root/TRY1/BigDataProtector*.tgz"

However, this just downloads the file in that location and stops after that. The file isn't extracted.

But when I comment the wget part and run the extract command it does get extracted.

How do I make both the commands consecutively?

Best Answer

Use Expect's native spawn command:

#!/usr/bin/expect
cd /root/TRY1/
spawn wget --http-user $user --http-password $password $url
spawn bash -c "tar -xzvf /root/TRY1/BigDataProtector*.tgz"

Or prevent wget from writing to the terminal with --quiet argument:

#!/usr/bin/expect
cd /root/TRY1/
exec wget --quiet --http-user $user --http-password $password $url
exec bash -c "tar -xzvf /root/TRY1/BigDataProtector*.tgz"

wget's progress bar causes Expect to fail when it is called with exec.