Skip to content

Instantly share code, notes, and snippets.

@adambarthelson
Last active August 18, 2019 21:29
Show Gist options
  • Save adambarthelson/a0382beaf1ccb48e4c5dcf09f089e0e3 to your computer and use it in GitHub Desktop.
Save adambarthelson/a0382beaf1ccb48e4c5dcf09f089e0e3 to your computer and use it in GitHub Desktop.
An Expect script to automate creating a new user for CloudHSM and activating the HSM initially by updating the admin password
#!/usr/bin/expect -f
set adminpassword [lindex $argv 0]
set newusername [lindex $argv 1]
set newuserpwd [lindex $argv 2]
set timeout 5
spawn /opt/cloudhsm/bin/cloudhsm_mgmt_util /opt/cloudhsm/etc/cloudhsm_mgmt_util.cfg
expect -re "aws-cloudhsm*" {
send "enable_e2e\r"
send "loginHSM CO admin $adminpassword\r"
expect -re "success*"
send "\r"
send "createUser CU $newusername $newuserpwd\r"
expect -re "continue*"
send "y\r"
expect -re "success"
send "\r"
send "listUsers\r"
send "\r"
send "quit\r"
}
exit
#!/usr/bin/expect -f
set adminpassword [lindex $argv 0]
set timeout 5
spawn /opt/cloudhsm/bin/cloudhsm_mgmt_util /opt/cloudhsm/etc/cloudhsm_mgmt_util.cfg
expect -re "aws-cloudhsm*" {
send "enable_e2e\r"
send "loginHSM PRECO admin password\r"
expect -re "success*"
send "\r"
send "changePswd PRECO admin $adminpassword\r"
expect -re "continue*"
send "y\r"
expect -re "CAUTION*"
send "\r"
send "logoutHSM\r"
send "\r"
expect -re ""
}
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment