Created
July 10, 2018 18:44
-
-
Save Scuilion/168bb38e07fabab6949bf39733a5f44e to your computer and use it in GitHub Desktop.
Expect Script to add user to group where usermod is not usuable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
set user [lindex $argv 0]; | |
set hosts { | |
"host1" "host2" | |
} | |
stty -echo | |
send_user -- "Enter your password:" | |
expect_user -re "(.*)\n" | |
send_user "\n" | |
stty echo | |
set pass $expect_out(1,string) | |
proc add_to_host { host user pass } { | |
spawn ssh -t $user@${host} {sudo sed -i -r 's:(docker\:.*):\1,koneal:' /etc/group} | |
expect { | |
"yes/no" { | |
send "yes\r" | |
exp_continue | |
} | |
"*?assword" { | |
send "$pass\r" | |
} | |
} | |
expect "*?assword for" {send "$pass\r"} | |
expect "Connection to" | |
} | |
foreach x $hosts { | |
set running [add_to_host $x $user $pass] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment