?
Solved

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.

Posted on 2014-08-27
6
Medium Priority
?
152 Views
Last Modified: 2014-09-03
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
0
Comment
Question by:Bryant
  • 3
  • 2
6 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40288947
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
 

Author Comment

by:Bryant
ID: 40288976
Thanks for your help with the original script and this one. The above format would be perfect.
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40289041
But it can display the user attributes with the -c option:

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

Open in new window

;)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40289082
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
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 40289351
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
 

Author Closing Comment

by:Bryant
ID: 40300952
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question