Skip to content

Instantly share code, notes, and snippets.

@dgvncsz0f
Last active February 3, 2016 17:19
Show Gist options
  • Save dgvncsz0f/0e9c1265fb4579557705 to your computer and use it in GitHub Desktop.
Save dgvncsz0f/0e9c1265fb4579557705 to your computer and use it in GitHub Desktop.
cache-pw
#!/usr/bin/expect -f
set spassword ""
set vpassword ""
set name "cache-pw"
set timeout 300
eval spawn -noecho [lrange $argv 0 [llength $argv]]
proc read_sudo_passwd {} {
global spassword
global name
if { $spassword == "" } {
send_user "($name) password: "
expect_user -re "(.*)\r"
set spassword $expect_out(1,string)
} else {
send_user "($name) using cache"
sleep 1
}
}
proc read_vault_passwd {} {
global vpassword
global name
if { $vpassword == "" } {
send_user "($name) password: "
expect_user -re "(.*)\r"
set vpassword $expect_out(1,string)
} else {
send_user "($name) using cache"
sleep 1
}
}
proc purge_cache {} {
global vpassword
global spassword
global name
send_user "($name) purging cache\n"
set vpassword ""
set spassword ""
}
interact \
~. {
purge_cache
} -o \
-nobuffer -re "SUDO password: $" {
read_sudo_passwd
send "$spassword\n"
} -nobuffer -re "Vault password: $" {
read_vault_passwd
send "$vpassword\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment