-
Notifications
You must be signed in to change notification settings - Fork 17
/
get_password.sh
30 lines (24 loc) · 899 Bytes
/
get_password.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
set -e
# Check if jq is installed
if ! [ -x "$(command -v jq)" ]; then
>&2 echo "Error: jq is not installed"
exit 1
fi
# Parse instance ID from input JSON
instanceid=$(jq -r '.instanceid')
# Get username and password from instance output
user=$(aws ec2 get-console-output --instance-id $instanceid --output text --no-paginate | grep "the default application username is" | awk -F "'" '{print $2}')
password=$(aws ec2 get-console-output --instance-id $instanceid --output text --no-paginate | grep "Setting Bitnami application password to" | awk -F "'" '{print $2}')
# Check if username and password were successfully retrieved
if [ -z "$user" ] || [ -z "$password" ]; then
>&2 echo "Error: Unable to retrieve username or password from instance output"
exit 1
fi
# Generate and print output JSON
cat <<EOF | jq -c
{
"user": "$user",
"password": "$password"
}
EOF