• Update SSM agent to each EC2 via Bat and bash script


    1. copy the instance id from aws console to file 

    2. remove the , from file

    sed -i 's/,//g' file
    

    3. get ip address list to file2

    $ cat getip.sh 
    #!/bin/bash
    for id in `cat file`
    	do
    	#echo $id >> file2
    	aws ec2 describe-instances --instance-ids $id | grep PrivateIpAddress  | head -1 | awk -F ":" '{print $2}' | sed 's/[",]//g' >> file2
    	done
    

    4. copy file2 to host.txt, 

    5. create inssm.bat 

    @echo off
    net use x:  \10.xx.xx.241Share /user:joinad password
    x:
    
    REM “Replace your codes starts from here”
    Ec2Install.exe /sp- /silent /norestart
    REM “replace your codes end of here.”
    if %ERRORLEVEL% NEQ 0 goto failed
    echo "SSM agent updated DONE!"
    
    cd ..
    echo %computername% %date% %time% >> ComputerList.txt
    echo "Updating of SSM agent succeeded. "
    goto end
    
    :faile
    echo $%computername% %date% %time% >> ComputerList.txt
    echo "Updating of SSM agent failed. "
    
    :end
    c:
    net use x: /delete

    6. run inssm.bat script to remote host via psexec

    for /F "tokens=*" %%A in (host.txt) do C:PSToolsPsExec.exe \%%A -u admin -p "pwd" -c -w c:/ "C:inssm.bat"
    

      

      

      

  • 相关阅读:
    元宇宙通证
    高性能公链
    区块链不可能三角
    搭建自己的在线API文档系统
    windows 安装python环境
    golang beego项目的正确开启方法
    人生发财靠康波
    蒙代尔不可能三角
    Kubernetes 部署Dashboard UI
    Kubernetes 使用kubeadm创建集群
  • 原文地址:https://www.cnblogs.com/oskb/p/9669858.html
Copyright © 2020-2023  润新知