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 [email protected] & for some its [email protected].
ssh -i "prod-key-pair.pem" [email protected] ssh -i "sandbox-key-pair.pem" [email protected] '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?