admin管理员组文章数量:1431406
I have an SSM environment in AWS, and I have client machines that are joining without any issues. I am able to remote connect to the terminal and run commands, everything works up to this point.
Now I am trying to run terminal commands on the devices en masse. So I would like to, for example, run this:
echo 192.168.1.1 MyServer.domain >> /etc/hosts
apt install realmd
echo MyPassword | realm join -v --user=MyUsername domain
sudo reboot
So to package this script up in a tidy little unit of some kind that I can push out to devices as I require. But I can't seem to find any way that this can be done.
I have an SSM environment in AWS, and I have client machines that are joining without any issues. I am able to remote connect to the terminal and run commands, everything works up to this point.
Now I am trying to run terminal commands on the devices en masse. So I would like to, for example, run this:
echo 192.168.1.1 MyServer.domain >> /etc/hosts
apt install realmd
echo MyPassword | realm join -v --user=MyUsername domain
sudo reboot
So to package this script up in a tidy little unit of some kind that I can push out to devices as I require. But I can't seem to find any way that this can be done.
Share Improve this question edited Nov 19, 2024 at 7:36 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Nov 19, 2024 at 6:39 BisclavretBisclavret 1,35110 gold badges40 silver badges71 bronze badges3 Answers
Reset to default 1maybe I'm misunderstanding the question, but SSM has a concept of "Documents" where you can store your scripts and supports a "Run Command" which can be used to run the document against your "fleet" of machines.
It even supports rate controls and more advanced feature.
Link for the documentation can be found here: https://docs.aws.amazon/systems-manager/latest/userguide/send-commands-multiple.html
you can try this script :
#!/bin/bash
instances=(i-instance-1 i-instance-2)
for instance in "${instances[@]}"; do
aws ssm send-command --document-name "AWS-RunShellScript"\
--targets "Key=instanceIds,Values=$instance"\
--parameters 'commands=["echo 192.168.1.1 MyServer.domain >> /etc/hosts","apt install realmd","echo MyPassword | realm join -v --user=MyUsername domain","reboot"]'
done
Try the following:
aws ssm send-command \
--document-name "AWS-RunShellScript" \
--targets '[{"Key":"InstanceIds","Values":["instance-id"]}]' \
--parameters '{"commands":["#!/bin/bash","echo 192.168.1.1 MyServer.domain >> /etc/hosts","apt install realmd","echo MyPassword | realm join -v --user=MyUsername domain","sudo reboot"]}'
For your instances, use an array with your instance ids in it. You would run this from your machine that has the aws cli on it and it would connect to all your remote instances. Each line of your shell script would be a separate command in quotation marks.
Here is the reference I found on the AWS documentation for future reference: https://docs.aws.amazon/systems-manager/latest/userguide/walkthrough-cli.html#walkthrough-cli-example-3
本文标签: linuxUsing SSM to push terminal commandsStack Overflow
版权声明:本文标题:linux - Using SSM to push terminal commands - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745583310a2664748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论