Bash Script to pull ipa server name on 500 servers

Hello All,
I need help writing a bash script that will run on 500 LINUX servers and do the following:

  1. Capture the ipa_server name from /etc/sssd/sssd.conf on a list of 500 servers in the ipahosts file.

  2. Write to a file outputing only server name and IPA server name.

Root ssh keys are enabled on all servers so automated login will occur. I really need help just extracting ONLY the IPA server information out of the file. I was playing around with grep and awk but haven't figured out the exact syntax.

Appreciate any help with this, Thanks

So far I have this:

#!bin/bash
for i in $(cat ipahosts)
do
hostname
cat /etc/sssd/sssd.conf >>ipa_servers_list
done

For those of us who are not using Linux servers, please show us the contents of /etc/sssd/sssd.conf on one of your servers (in CODE tags) and point out the contents of that file that you are trying to extract from each of your 500 servers.

Presumably, if you're trying to extract particular data from sssd.conf on each of your servers into a single file on the system where your are running your script, you will want something more like:

#!bin/bash
while read -r host in $(cat ipahosts)
do	ssh $host <<-EOF
		ipaserver=$(awk 'awk commands to extract ipahostname' /etc/sssd/sssd.conf)
		printf 'host: %s ipahost: %s\n' "$(hostname)" "$ipaserver"
	EOF
done < ipahosts > ipa_servers_list

(Note that with a here-document like this, that is a leading tab in front of the EOF and it must be a tab character, not spaces, to properly terminate the here-document.)

Where is that script going to run? Where is the "ipahosts" file located? How are ipahosts' entries, "sssd.conf" contents, and hostname s connected? Where should the result file reside?

Hello All,

Thanks for everyones help with this. Below is the actual working script I used to accomplish my task of sshing to over 500 remote RHEL LINUX servers using ssh, run remote commands, grep for IPA server and then outputt to a file or the screen.

SAMPLE /etc/sssd/sssd.conf:
###################################

[root@xyz_server ~]# cat /etc/sssd/sssd.conf
[domain/]
cache_credentials = True
krb5_store_password_if_offline = True
krb5_realm = UNIX-PROD
ipa_domain = sampledomain.com
id_provider = ipa
auth_provider = ipa
access_provider = ipa
ipa_hostname = ipahostname.domain.com
chpass_provider = ipa
ipa_server = ipaserver.domain.com, ipaserver2.domain.com
ldap_tls_cacert = /etc/ipa/ca.crt
[sssd]
services = nss, pam, ssh
config_file_version = 2
domains = sampledomain.com
[nss]
[pam]
[sudo]
[autofs]
[ssh]

################################################################
WORKING SSH BASH SSH SCRIPT TO REMOTE SERVER USING ROOT SSH KEYS, RUN COMMANDS ON REMOTE SERVER AND OUTPUT TO SCREEN OR FILE
OUTPUT TO FILE
################################################################

<root@xyzserver:~> # cat script.bsh
#!/bin/bash
for x in `cat serverlistfilename`; do echo $x>>outputname.txt; ssh $x "grep 'ipaserver1\|ipaserver4\|ipaserver3' /etc/sssd/sssd.conf">>output.txt
done
<root@xyzserver:~> #

OUTPUT TO SCREEN:

<root@xyzserver:~> # cat script.bsh
#!/bin/bash
for x in `cat serverlistfilename`; do echo $x; ssh $x "grep 'ipaserver1\|ipaserver2\|ipaserver3' /etc/sssd/sssd.conf"
done
<root@xyzserver:~> #

-vtowntechy :o)