Skip to content

Instantly share code, notes, and snippets.

@Scuilion
Created July 10, 2018 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scuilion/168bb38e07fabab6949bf39733a5f44e to your computer and use it in GitHub Desktop.
Save Scuilion/168bb38e07fabab6949bf39733a5f44e to your computer and use it in GitHub Desktop.
Expect Script to add user to group where usermod is not usuable.
#!/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