- 最新
- 最多得票
- 最多評論
Hello,
I reviewed your ask along with the Github page that you referred, and tried to create an Automation Document. I was able to add the Bash Script onto the Step.
For you to do the same, please follow the below steps:
- Give a “Step Name”.
- Keep the “Action Type” on “Run a command on a managed instance”
- Keep the “Document name” field type “AWS-RunShellScript”.
- Let “Document name” and “InstanceIDs” also remain the same ie. AWS-RunShellScript and {{ START_QUERY_AWS_DBInstanceId.DBInstanceId }} respectively.
- Now, open “Additional inputs” and under “Input Name”, choose “Parameters” and add the below snippet in the “Input value”.
commands:
- '#!/bin/bash'
- 'SAPProfile=
grep -o ''pf=[^[:space:]]*'' /usr/sap/sapservices | grep _HDB
' - 'SID=
echo ${SAPProfile} | awk -F "/" ''{print $4}''
' - 'SYSTEMNO=
echo ${SAPProfile} | awk -F "/" ''{print $7}'' | awk -F "_" ''{print $2}'' | sed ''s@^[^0-9]*\([0-9]\+\).*@\1@''
' - 'echo "Running /usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function StartService ${SID}"'
- '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function StartService ${SID}'
- '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function WaitforServiceStarted 10 2'
- 'echo "Running /usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function GetSystemInstanceList"'
- '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function GetSystemInstanceList'
- 'if [ $? -eq 0 ]'
- then
- 'echo "There is a system here, I am going to use start"'
- '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function StartWait 600 2'
- else
- 'echo "There is no service running for instance number ${SYSTEMNO} "'
- exit 1
- fi
- '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function GetProcessList'
- 'if [ $? -eq 3 ]'
- ' then'
- ' echo "
date +%F\ %T
: The HANA Database Started Successfully"' - ' else'
- ' echo "The return code was $? "'
- ' exit 1'
- ' fi'
(Note: Kindly note that the bullets that you observe are basically hyphens(-), and the above snippet is copied from SSMStopStartSAPv1.0.yml of the GitHub page: https://github.com/aws-samples/aws-ssm-automation-for-start-stop-sap)
- Similarly, you can now repeat the for the steps that require bash script to be included.
Thank you!
I had the same problem today. I followed steps 1-4 from the previous answer but I was unable to add the commands as the input was expected as StringMap(Format : {"Env": "Prod"}).
This worked for me : Follow Previous post's steps 1-4 and then for Step-5: Click “Additional inputs” --> Under “Input Name”, choose “Parameters” and in the "Input Value" dialogue box add commands like this :
commands:
- '#!/bin/bash'
- 'command1'
- 'command2'
I directly entered the commands and I was missing the 'commands:' param in the Input Value, which is actually expected to be mentioned.
Alternatively, you can directly add the commands in the "Editor" section which is more easier. An example SSM Automation document :
schemaVersion: '0.3'
parameters:
VALUES:
type: String
mainSteps:
- name: RunCommand
action: 'aws:runCommand'
inputs:
DocumentName: AWS-RunShellScript
InstanceIds:
- i-xxxxx
Parameters:
commands:
- '#!/bin/bash'
- 'touch /home/ec2-user/ssm.txt'
- 'echo {{VALUES}} >> /home/ec2-user/ssm.txt'
相關內容
- 已提問 1 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 4 年前
- AWS 官方已更新 5 個月前
i keep getting this error when trying to follow your instructions: is of type String, but expected type is StringMap. any idea why this might be?