I have a script that will let me get multiple user information across multiple servers but I need to to know more info from lsuser but can't get it to work.

I need to somehow get this information to execute after lsuser is done in my script

awk -F : '{print $1","$4","$7","$16","$22","$24", "$44","$47}'

but i cant figure out how to make it work. Those numbers represent sections of lsuser like login, expiration, unsuccessful attempts, etc. My script is below. Thanks in advance.

!/bin/bash
OUTPUT=/home/userid/User_List.csv
for i in $(cat master/numbers)
do
   echo -e "\n$i\c"
   ssh -o BatchMode=yes isp1.$i 'for u in '$(cat users.txt)'; do lsuser -a $u ; done 2>/dev/null' | \
   xargs -I% echo ",%\c"
done | grep -v "^$" >$OUTPUT
#uuencode User_List.csv User_List.csv | mail -s "User List" me@myaddress.com
BryantAsked:
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:
Hi again,

the original script (which I wrote for you) just checks for the existence of given userids on certain hosts to then list the userids found, one line per checked host.

This output format cannot really be used to show more info than just usernames. An attemt to augment this info would make the output virtually unreadable.

We could produce an output format like

*** hostname1 ***
username1,expiration,unsuccessful_login_count,more_info,even_more_info_...,...
username2,expiration,unsuccessful_login_count,more_info,even_more_info_...,...
username3,expiration,unsuccessful_login_count,more_info,even_more_info_...,...
...
usernameN,...,...,...

*** hostname2 ***
username1,expiration,unsuccessful_login_count,more_info,even_more_info_...,...
username2,expiration,unsuccessful_login_count,more_info,even_more_info_...,...
username3,expiration,unsuccessful_login_count,more_info,even_more_info_...,...
...
usernameN,...,...,...

*** hostname3 ***
username1,expiration,unsuccessful_login_count,more_info,even_more_info_...,...
username2,expiration,unsuccessful_login_count,more_info,even_more_info_...,...
username3,expiration,unsuccessful_login_count,more_info,even_more_info_...,...
...
usernameN,...,...,...

Please let me know if the above would meet your requirements, otherwise please tell me which output format you'd like to see.
0
BryantAuthor Commented:
Thanks for your help with the original script and this one. The above format would be perfect.
0
MikeOM_DBACommented:
But it can display the user attributes with the -c option:

#name:id:pgrp:groups:home:shell

Open in new window

;)
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

woolmilkporcCommented:
Find the script below.

Important NOTE:

lsuser does not list attributes which have no value, not even in the form "::".
So if there is for example no GECOS then this field will be completely left out, the following fields will shift to the left.
That's why I had to name the desired fields instead of extracting them by position, and that's also why I left the
column headers  starting with "#name:..." in place for every listed user.
Failure doing so would lead to heavy misinterpretation of the displayed values.
Next, since the group list often contains commas I left the column separator as ":"
#!/bin/bash
OUTPUT=/home/userid/User_List.csv
for i in $(cat master/numbers)
do
   echo -e "\n *** isp1.$i ***"
   ssh -o BatchMode=yes isp1.$i 'for u in '$(cat userlist)';
                             do lsuser -c -a groups gecos ttys SYSTEM pwdwarntime stack_hard tty_last_login $u ;
                                done 2>/dev/null'
done > $OUTPUT

Open in new window

Should I have made mistakes in specifying the desired fields please adjust line 7 of the script accordingly,
but please note that "name" is not a valid attribute because "lsuser" displays the name automatically in the first position.
0
woolmilkporcCommented:
The following version will display non-existent attributes as "::". Column headers are shown once per server.
#!/bin/bash
OUTPUT=/home/userid/User_List.csv
ATTRS="groups gecos ttys SYSTEM pwdwarntime stack_hard tty_last_login"
for i in $(cat master/numbers)
do
   echo -e "*** isp1.$i ***"
   echo -e "#name:\c"; echo -e $ATTRS | tr " " ":"; echo
   ssh -o BatchMode=yes isp1.$i 'for u in '$(cat userlist)';
                             do echo "$u\c" ; for a in '$ATTRS'
                              do A="$(lsuser -c -a $a $u | awk -F: "!/^#/ {print \$2}")"
                                echo  ":$A\c"
                                done
                                 echo
                                 done 2>/dev/null'
                                 echo
done | grep -v "^[a-zA-Z0-9]*:*$" > $OUTPUT

Open in new window

Unfortunately I have to leave now for a business trip and won't be back until Monday.

Good luck!

wmp
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
BryantAuthor Commented:
This solution gave me 90% of everything I needed and I made a few modes to cover the rest.

 Thanks WMP.. You're Awesome!
0
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
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.