Question

I know I can run bash scripts placed inside gist.github.com using the following:

bash -c "$(curl -fsSL https://raw.github.com/gist/5126919)" <arg0> <arg1>

How do I do the same for expect scripts?

I have a sample here:

https://gist.github.com/simkimsia/5126919

#!/usr/bin/expect -f

set CHANGESHELL_FOR_USER [lindex $argv 0];
set PASSWORD_OF_USER [lindex $argv 1];

########################################
## switch to another user
## read this http://stackoverflow.com/a/1988255/80353
########################################
sudo -u $CHANGESHELL_FOR_USER -H sh -c "chsh -s /bin/bash" 

expect "*?assword:*" {send -- "$PASSWORD_OF_USER\r";}
expect eof

My purpose is to chsh for a particular user.

Was it helpful?

Solution

Bash and ksh support process substitution so you can try like this:

expect <(curl ...) arg1 arg2 ...

The only problem I can think of is that the value of $argv0 is not what we usually expect. You may consider hard coding it in the script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top