Exec Command
Execute arbitrary system calls and replaces templated environmental variables with Keeper vault secrets

exec command

To perform magic environmental variable substitution, use the ksm exec command.
Parameters:
System call or script to run with replaced environment variables
format: ksm exec -- <SYSTEM CALL OR SCRIPT>
(1) Example Linux / Mac script
my_script.sh
1
#!/bin/bash
2
3
# Bash script that pulls Keeper secrets
4
5
connect_db() {
6
echo "Database Password:" $DB_PASSWORD
7
}
8
9
call_stripe() {
10
echo "API Key:" $API_KEY
11
}
12
13
connect_db
14
call_stripe
Copied!
Set a couple environmental variables then execute the script:
1
$ export DB_PASSWORD="keeper://XXX/field/password"
2
$ export API_KEY="keeper://XXX/custom_field/API Key"
3
4
$ ksm exec -- ./my_script.sh
5
6
Database Password: [email protected]
7
API Key: sk_test_MY2A30Ofg6Ukkq2NjMQVo87c
Copied!
(2) Example Windows batch file
1
C:\> ksm exec -- my_script.bat
Copied!
(3) Example PowerShell script
1
PS C:\> ksm exec -- powershell my_script.ps1
Copied!

Environment Variable Replacement

Environment variables must be templated so that the CLI can find and replace them correctly. For example:
1
export DB_PASSWORD="keeper://XXX/field/password"
2
export API_KEY="keeper://XXX/custom_field/API Key"
Copied!
See the Keeper Notation documentation for more information on notation query format and capabilities

Example Shell Script

Below is a Linux bash script example. Before an application is started or a command is run, any environmental variables that start with keeper:// will be replaced with secret values from the vault. Make sure to replace XXXX with the Record UID of the secret.
1
export MY_PASSWORD=keeper://XXXX/field/password
2
export MY_OTHER_PASSWORD=keeper://XXXX/field/password[0]
3
export MY_LAST_NAME=keeper://XXXX/custome_field/Name 2[last]
4
export MY_SECOND_PHONE=keeper://XXXX/custome_field/phone[1][number]
Copied!
Here's a simple bash script that prints the secrets to the console:
1
#!/usr/bin/env bash
2
echo
3
echo "My Password = \${MY_PASSWORD}"
4
echo "Other Password = \${MY_OTHER_PASSWORD}"
5
echo "My Last Name = \${MY_LAST_NAME}"
6
echo "My Second Phone = \${MY_SECOND_PHONE}"
Copied!
And here's the output from executing the bash script with ksm exec
1
$ ksm exec -- ./my_script.sh
2
3
My Password = $71387feh24fE%4416ffFHA
4
Other Password = YYFash328f^F^@#Fsdfjhsgblqef'f;
5
My Last Name = Smith
6
My Second Phone = 123-456-7890
Copied!

Last modified 1mo ago