0
I have almost 150 ec2-instances in an account. I want to extract some system info from each instance. I am aware that I can individually login into each system and get the information using the particular command. But I want all the information in one go. I can write a simple script, but the problem is while I have a bastion host and then I need to ssh into each instance & the username is different. Example for some instance its ec2-user@2.2.2.2 & for some its centos@3.3.3.3.
ssh -i "prod-key-pair.pem" ec2-user@ec2-1-9-1-2.compute-1.amazonaws.com ssh -i "sandbox-key-pair.pem" centos@1.1.4.2 'bash -s' << EOF
cat /etc/*-release|grep -m 1 NAME >>os_detail.txt
ifconfig | grep inet |head -1 |awk -F ' ' '{print $2}' >>os_detail.txt
EOF
My question is what is the way where it can pick both centos & ec2-user one by one & if it fails using centos then it should try ec2-user. Secondly, the two commands when executed are creating the files in the server but I want those files in my local system from where I am running the script.
Any pointers on how I can solve this issue?
Please note that https://superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill – 2018-05-04T20:12:02.633@DavidPostill : I have updated the question accordingly – Prashast – 2018-05-04T20:51:04.710