How to run a file from URL using Expect?

Viewed 396

In an expect script, I'd like to download a file and execute it. I've tried these options so far:

Attempt 1 - Simply download and execute

#!/usr/bin/expect -f

spawn wget mysite.com/file.sh
spawn /bin/sh file.sh

The /bin/sh command executes before the file finishes downloading

Attempt 2 - Pipe content to executable

#!/usr/bin/expect -f

spawn /bin/sh <(curl -s mysite.com/file.sh)

I get this error:

/bin/sh: <(curl: No such file or directory
send: spawn id exp6 not open
while executing

I tried escaping characters a few different ways

Attempt 3 - Use eval

#!/usr/bin/expect -f

spawn eval "\$(/bin/sh <\(curl -s mysite.com/file.sh\))"

This gives this error:

couldn't execute "eval": no such file or directory
while executing

I tried with and without escaping characters

1 Answers

system <args> passes the arguments to sh. Therefore you can use the && operator to execute the script after it is executed.

#!/usr/bin/expect -f

system wget mysite.com/file.sh && ./file.sh

Or if you don't want to save the script at all:

#!/usr/bin/expect -f

system curl mysite.com/file.sh | /bin/sh
Related