I cannot figure this out because my bash skills aren't that strong and I haven't been able to find an existing script to do this after much googling.
I use pslurp to grab the /etc/passwd file from multiple servers. That puts the /etc/passwd in a directory structure /servername/password
pslurp -h serverlist -L localdir /etc/passwd password
Then I need to take each of those password files that I just grabbed and adjust them to only show the usernames of users with the ability to login interactively. I do that by excluding any users with a shell of /sbin/nologin for each of the /servername/password files and output to a new file
grep -v "/sbin/nologin$" password | cut -d: -f1 > /servername/newfile
Once I've got that, I'll need to get all of the /servername/newfile contents into 1 combined file with a format of
servername
list contents of /servername/newfile under each servername
servername
list contents of /servername/newfile under each servername
and so on ...
I've been working on this for a couple of days but just can't get it to happen. Please help!
So long as you have set up passwordless login by
sshto the servers to collect/etc/passwdfrom (or want to just enter the password for each when prompted), you don't needpslurpor any other canned utility, all you need issshandawk. For example to retrieve and combine all/etc/passwdfiles from a list of servers removing all entries that containnologinorfalse(for/bin/false) and writing them out in a format of:All you need is a simple array containing the server names and the following, e.g.
That will create
newfilewith the format and contents you describe without using any temporary files locally.If you want the flexibility to redirect the output to
stdoutor any file of your choosing, just remove the brace-enclosed grouping an redirection within the script and redirect the output (or let it print tostdout) when you run the script.There are endless ways to approach this, but this is one that is relatively straight-forward. For instance, if you do not have bash on the servers, but are limited to POSIX shell, you can use a simple list of servers instead of an array and the remainder would work as is.