AIX/Linux - Shell script to collect /etc/passwd and /etc/group

I need to collect the /etc/passwd and /etc/group files from 50 odd servers. Of course, there is no way I'm going to logon to those 50 servers and ftp one by one. I needed help to come up with a script that will allow me from my jump server to go out and collect these files using a flat file containing the list of servers. Any help on this?
AIX25Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
Do you need separate files for passwd and group?

If you don't, just run this:

while read server
  do
    ssh $server 'echo "Contents of PASSWD"; cat /etc/passwd; echo "Contents of GROUP" ; cat /etc/group' >/tmp/$server.passwd_group
  done < list_of servers

If you need separate files, the simplest way is this:

while read server
  do
    ssh $server 'echo "Contents of PASSWD"; cat /etc/passwd'  >/tmp/$server.passwd
    ssh $server 'echo "Contents of GROUP" ; cat /etc/group' >/tmp/$server.group
  done < list_of servers

You should have public key access to the servers, otherwise you would have to enter the password 50 times (first version) or even 100 times (second version).

wmp
0
AIX25Author Commented:
I'm doing the 1 file option and I don't have my pub key setup, but I'm ok with that for now till I do set it up.

Problem though...I ran the script and it worked on the first server in the list and than it broke out of it and went back to the prompt. Any ideas why?
0
woolmilkporcCommented:
Yes, that's a mistake of mine, sorry!

We must use the "-n" flag of ssh to keep it from reading stdin.

ssh -n $server 'echo "Contents of PASSWD"; cat /etc/passwd; echo "Contents of GROUP" ; cat /etc/group' >/tmp/$server.passwd_group
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.